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 | |
---|
11 | namespace xios { |
---|
12 | |
---|
13 | CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis) |
---|
14 | : CAxisAlgorithmTransformation(axisDestination, 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->n_glo.getValue()) |
---|
22 | { |
---|
23 | ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)", |
---|
24 | << "Zoom size is greater than global size of axis source" |
---|
25 | << "Global size of axis source " <<axisSource->getId() << " is " << axisSource->n_glo.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 | */ |
---|
35 | void CAxisAlgorithmZoom::computeIndexSourceMapping() |
---|
36 | { |
---|
37 | StdSize niSource = axisSrc_->n.getValue(); |
---|
38 | StdSize ibeginSource = axisSrc_->begin.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 | std::map<int, std::vector<double> >& transWeight = this->transformationWeight_; |
---|
48 | for (StdSize idx = 0; idx < ni; ++idx) |
---|
49 | { |
---|
50 | transMap[ibegin+idx].push_back(ibegin+idx); |
---|
51 | transWeight[ibegin+idx].push_back(1.0); |
---|
52 | } |
---|
53 | |
---|
54 | updateZoom(); |
---|
55 | updateAxisDestinationMask(); |
---|
56 | } |
---|
57 | |
---|
58 | /*! |
---|
59 | After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated |
---|
60 | */ |
---|
61 | void CAxisAlgorithmZoom::updateZoom() |
---|
62 | { |
---|
63 | axisDest_->global_zoom_begin = zoomBegin_; |
---|
64 | axisDest_->global_zoom_size = zoomSize_; |
---|
65 | } |
---|
66 | |
---|
67 | /*! |
---|
68 | Update mask on axis |
---|
69 | Because only zoomed region on axis is not masked, the remaining must be masked to make sure |
---|
70 | correct index be extracted |
---|
71 | */ |
---|
72 | void CAxisAlgorithmZoom::updateAxisDestinationMask() |
---|
73 | { |
---|
74 | StdSize niMask = axisDest_->mask.numElements(); |
---|
75 | StdSize iBeginMask = axisDest_->begin.getValue(); |
---|
76 | StdSize globalIndexMask = 0; |
---|
77 | std::map<int, std::vector<int> >& transMap = this->transformationMapping_; |
---|
78 | std::map<int, std::vector<int> >::const_iterator ite = (transMap).end(); |
---|
79 | for (StdSize idx = 0; idx < niMask; ++idx) |
---|
80 | { |
---|
81 | globalIndexMask = iBeginMask + idx; |
---|
82 | if (transMap.find(globalIndexMask) == ite) |
---|
83 | (axisDest_->mask)(idx) = false; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | } |
---|