source: XIOS/trunk/src/transformation/axis_algorithm_zoom.cpp @ 624

Last change on this file since 624 was 624, checked in by mhnguyen, 8 years ago

Final tests of zoom and inverse on axis

+) Modify test_client and test_complete to work with new grid definition
+) Correct some bugs causing memory leak
+) Clean abundant code
+) Add more comments to new files

Test
+) On Curie
+) test_client and test_complete pass with correct results

File size: 2.6 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
11namespace xios {
12
13CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)
14: CAxisAlgorithmTransformation(axisDestination, axisSource), axisDest_(axisDestination), axisSrc_(axisSource)
15{
16  zoomAxis->checkValid(axisSource);
17  zoomBegin_ = zoomAxis->zoom_begin.getValue();
18  zoomEnd_   = zoomAxis->zoom_end.getValue();
19  zoomSize_  = zoomAxis->zoom_size.getValue();
20
21  if (zoomSize_ > axisSource->size.getValue())
22  {
23    ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)",
24           << "Zoom size is greater than size of axis source"
25           << "Size of axis source " <<axisSource->getId() << " is " << axisSource->size.getValue()  << std::endl
26           << "Zoom size is " << zoomSize_ );
27  }
28
29  computeIndexSourceMapping();
30}
31
32/*!
33  Compute the index mapping between axis on grid source and one on grid destination
34*/
35void CAxisAlgorithmZoom::computeIndexSourceMapping()
36{
37  StdSize niSource = axisSrc_->ni.getValue();
38  StdSize ibeginSource = axisSrc_->ibegin.getValue();
39  StdSize iendSource = ibeginSource + niSource - 1;
40
41  StdSize ibegin = std::max(ibeginSource, zoomBegin_);
42  StdSize iend = std::min(iendSource, zoomEnd_);
43  StdSize ni = iend + 1 - ibegin;
44  if (iend < ibegin) ni = 0;
45
46  std::map<int, std::vector<int> >& transMap = this->transformationMapping_;
47  for (StdSize idx = 0; idx < ni; ++idx)
48  {
49    transMap[ibegin+idx].push_back(ibegin+idx);
50  }
51
52  updateZoom();
53  updateAxisDestinationMask();
54}
55
56/*!
57  After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated
58*/
59void CAxisAlgorithmZoom::updateZoom()
60{
61  axisDest_->global_zoom_begin = zoomBegin_;
62  axisDest_->global_zoom_size  = zoomSize_;
63}
64
65/*!
66  Update mask on axis
67  Because only zoomed region on axis is not masked, the remaining must be masked to make sure
68correct index be extracted
69*/
70void CAxisAlgorithmZoom::updateAxisDestinationMask()
71{
72  StdSize niMask = axisDest_->mask.numElements();
73  StdSize iBeginMask = axisDest_->ibegin.getValue();
74  StdSize globalIndexMask = 0;
75  std::map<int, std::vector<int> >& transMap = this->transformationMapping_;
76  std::map<int, std::vector<int> >::const_iterator ite = (transMap).end();
77  for (StdSize idx = 0; idx < niMask; ++idx)
78  {
79    globalIndexMask = iBeginMask + idx;
80    if (transMap.find(globalIndexMask) == ite)
81      (axisDest_->mask)(idx) = false;
82  }
83}
84
85}
Note: See TracBrowser for help on using the repository browser.