[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" |
---|
[933] | 10 | #include "axis.hpp" |
---|
| 11 | #include "grid.hpp" |
---|
| 12 | #include "grid_transformation_factory_impl.hpp" |
---|
| 13 | #include "zoom_axis.hpp" |
---|
[623] | 14 | |
---|
| 15 | namespace xios { |
---|
[933] | 16 | CGenericAlgorithmTransformation* 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(); |
---|
[623] | 28 | |
---|
[933] | 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 | } |
---|
| 35 | bool CAxisAlgorithmZoom::registerTrans() |
---|
| 36 | { |
---|
| 37 | CGridTransformationFactory<CAxis>::registerTransformation(TRANS_ZOOM_AXIS, create); |
---|
| 38 | } |
---|
| 39 | |
---|
[623] | 40 | CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis) |
---|
[630] | 41 | : CAxisAlgorithmTransformation(axisDestination, axisSource) |
---|
[623] | 42 | { |
---|
| 43 | zoomAxis->checkValid(axisSource); |
---|
[787] | 44 | zoomBegin_ = zoomAxis->begin.getValue(); |
---|
| 45 | zoomSize_ = zoomAxis->n.getValue(); |
---|
| 46 | zoomEnd_ = zoomBegin_ + zoomSize_ - 1; |
---|
[623] | 47 | |
---|
[666] | 48 | if (zoomSize_ > axisSource->n_glo.getValue()) |
---|
[623] | 49 | { |
---|
| 50 | ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)", |
---|
[666] | 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 |
---|
[623] | 53 | << "Zoom size is " << zoomSize_ ); |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
[624] | 57 | /*! |
---|
| 58 | Compute the index mapping between axis on grid source and one on grid destination |
---|
| 59 | */ |
---|
[827] | 60 | void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
[623] | 61 | { |
---|
[666] | 62 | StdSize niSource = axisSrc_->n.getValue(); |
---|
| 63 | StdSize ibeginSource = axisSrc_->begin.getValue(); |
---|
[623] | 64 | StdSize iendSource = ibeginSource + niSource - 1; |
---|
| 65 | |
---|
| 66 | StdSize ibegin = std::max(ibeginSource, zoomBegin_); |
---|
| 67 | StdSize iend = std::min(iendSource, zoomEnd_); |
---|
| 68 | StdSize ni = iend + 1 - ibegin; |
---|
| 69 | if (iend < ibegin) ni = 0; |
---|
| 70 | |
---|
[827] | 71 | this->transformationMapping_.resize(1); |
---|
| 72 | this->transformationWeight_.resize(1); |
---|
| 73 | |
---|
[833] | 74 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
| 75 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
[827] | 76 | |
---|
[623] | 77 | for (StdSize idx = 0; idx < ni; ++idx) |
---|
| 78 | { |
---|
| 79 | transMap[ibegin+idx].push_back(ibegin+idx); |
---|
[630] | 80 | transWeight[ibegin+idx].push_back(1.0); |
---|
[623] | 81 | } |
---|
| 82 | |
---|
| 83 | updateZoom(); |
---|
| 84 | updateAxisDestinationMask(); |
---|
| 85 | } |
---|
| 86 | |
---|
[624] | 87 | /*! |
---|
| 88 | After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated |
---|
| 89 | */ |
---|
[623] | 90 | void CAxisAlgorithmZoom::updateZoom() |
---|
| 91 | { |
---|
| 92 | axisDest_->global_zoom_begin = zoomBegin_; |
---|
[821] | 93 | axisDest_->global_zoom_n = zoomSize_; |
---|
[623] | 94 | } |
---|
| 95 | |
---|
[624] | 96 | /*! |
---|
| 97 | Update mask on axis |
---|
| 98 | Because only zoomed region on axis is not masked, the remaining must be masked to make sure |
---|
| 99 | correct index be extracted |
---|
| 100 | */ |
---|
[623] | 101 | void CAxisAlgorithmZoom::updateAxisDestinationMask() |
---|
| 102 | { |
---|
| 103 | StdSize niMask = axisDest_->mask.numElements(); |
---|
[666] | 104 | StdSize iBeginMask = axisDest_->begin.getValue(); |
---|
[623] | 105 | StdSize globalIndexMask = 0; |
---|
[833] | 106 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
| 107 | TransformationIndexMap::const_iterator ite = (transMap).end(); |
---|
[623] | 108 | for (StdSize idx = 0; idx < niMask; ++idx) |
---|
| 109 | { |
---|
| 110 | globalIndexMask = iBeginMask + idx; |
---|
| 111 | if (transMap.find(globalIndexMask) == ite) |
---|
| 112 | (axisDest_->mask)(idx) = false; |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | } |
---|