[624] | 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 | */ |
---|
[623] | 9 | #include "axis_algorithm_zoom.hpp" |
---|
| 10 | |
---|
| 11 | namespace xios { |
---|
| 12 | |
---|
| 13 | CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis) |
---|
[630] | 14 | : CAxisAlgorithmTransformation(axisDestination, axisSource) |
---|
[623] | 15 | { |
---|
| 16 | zoomAxis->checkValid(axisSource); |
---|
[787] | 17 | zoomBegin_ = zoomAxis->begin.getValue(); |
---|
| 18 | zoomSize_ = zoomAxis->n.getValue(); |
---|
| 19 | zoomEnd_ = zoomBegin_ + zoomSize_ - 1; |
---|
[623] | 20 | |
---|
[666] | 21 | if (zoomSize_ > axisSource->n_glo.getValue()) |
---|
[623] | 22 | { |
---|
| 23 | ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)", |
---|
[666] | 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 |
---|
[623] | 26 | << "Zoom size is " << zoomSize_ ); |
---|
| 27 | } |
---|
| 28 | |
---|
[827] | 29 | // computeIndexSourceMapping(); |
---|
[623] | 30 | } |
---|
| 31 | |
---|
[624] | 32 | /*! |
---|
| 33 | Compute the index mapping between axis on grid source and one on grid destination |
---|
| 34 | */ |
---|
[827] | 35 | void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
[623] | 36 | { |
---|
[666] | 37 | StdSize niSource = axisSrc_->n.getValue(); |
---|
| 38 | StdSize ibeginSource = axisSrc_->begin.getValue(); |
---|
[623] | 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 | |
---|
[827] | 46 | this->transformationMapping_.resize(1); |
---|
| 47 | this->transformationWeight_.resize(1); |
---|
| 48 | |
---|
| 49 | std::map<int, std::vector<int> >& transMap = this->transformationMapping_[0]; |
---|
| 50 | std::map<int, std::vector<double> >& transWeight = this->transformationWeight_[0]; |
---|
| 51 | |
---|
[623] | 52 | for (StdSize idx = 0; idx < ni; ++idx) |
---|
| 53 | { |
---|
| 54 | transMap[ibegin+idx].push_back(ibegin+idx); |
---|
[630] | 55 | transWeight[ibegin+idx].push_back(1.0); |
---|
[623] | 56 | } |
---|
| 57 | |
---|
| 58 | updateZoom(); |
---|
| 59 | updateAxisDestinationMask(); |
---|
| 60 | } |
---|
| 61 | |
---|
[624] | 62 | /*! |
---|
| 63 | After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated |
---|
| 64 | */ |
---|
[623] | 65 | void CAxisAlgorithmZoom::updateZoom() |
---|
| 66 | { |
---|
| 67 | axisDest_->global_zoom_begin = zoomBegin_; |
---|
[821] | 68 | axisDest_->global_zoom_n = zoomSize_; |
---|
[623] | 69 | } |
---|
| 70 | |
---|
[624] | 71 | /*! |
---|
| 72 | Update mask on axis |
---|
| 73 | Because only zoomed region on axis is not masked, the remaining must be masked to make sure |
---|
| 74 | correct index be extracted |
---|
| 75 | */ |
---|
[623] | 76 | void CAxisAlgorithmZoom::updateAxisDestinationMask() |
---|
| 77 | { |
---|
| 78 | StdSize niMask = axisDest_->mask.numElements(); |
---|
[666] | 79 | StdSize iBeginMask = axisDest_->begin.getValue(); |
---|
[623] | 80 | StdSize globalIndexMask = 0; |
---|
[827] | 81 | std::map<int, std::vector<int> >& transMap = this->transformationMapping_[0]; |
---|
[623] | 82 | std::map<int, std::vector<int> >::const_iterator ite = (transMap).end(); |
---|
| 83 | for (StdSize idx = 0; idx < niMask; ++idx) |
---|
| 84 | { |
---|
| 85 | globalIndexMask = iBeginMask + idx; |
---|
| 86 | if (transMap.find(globalIndexMask) == ite) |
---|
| 87 | (axisDest_->mask)(idx) = false; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | } |
---|