[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 | { |
---|
[1850] | 37 | return CGridTransformationFactory<CAxis>::registerTransformation(TRANS_ZOOM_AXIS, create); |
---|
[933] | 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 | } |
---|
[1202] | 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 | |
---|
[623] | 66 | } |
---|
| 67 | |
---|
[624] | 68 | /*! |
---|
| 69 | Compute the index mapping between axis on grid source and one on grid destination |
---|
| 70 | */ |
---|
[827] | 71 | void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
[623] | 72 | { |
---|
[1129] | 73 | // We use all index of source and destination to calculate the mapping index of zoom. |
---|
| 74 | // The server who receives the "zoomed" fields will decide whether it will forward these fields or write "real zoomed" fields into file |
---|
| 75 | // That means servers need to change to cover this problem. |
---|
[666] | 76 | StdSize niSource = axisSrc_->n.getValue(); |
---|
| 77 | StdSize ibeginSource = axisSrc_->begin.getValue(); |
---|
[623] | 78 | StdSize iendSource = ibeginSource + niSource - 1; |
---|
| 79 | |
---|
| 80 | StdSize ibegin = std::max(ibeginSource, zoomBegin_); |
---|
| 81 | StdSize iend = std::min(iendSource, zoomEnd_); |
---|
| 82 | StdSize ni = iend + 1 - ibegin; |
---|
| 83 | if (iend < ibegin) ni = 0; |
---|
| 84 | |
---|
[827] | 85 | this->transformationMapping_.resize(1); |
---|
| 86 | this->transformationWeight_.resize(1); |
---|
| 87 | |
---|
[833] | 88 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
| 89 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
[827] | 90 | |
---|
[1202] | 91 | if (!zoomIndex_.empty()) |
---|
[623] | 92 | { |
---|
[1202] | 93 | std::vector<int>::iterator itZoomBegin, itZoomEnd; |
---|
| 94 | itZoomBegin = std::lower_bound(zoomIndex_.begin(), zoomIndex_.end(), ibeginSource); |
---|
| 95 | itZoomEnd = std::upper_bound(zoomIndex_.begin(), zoomIndex_.end(), iendSource); |
---|
| 96 | for (; itZoomBegin != itZoomEnd; ++itZoomBegin) |
---|
| 97 | { |
---|
| 98 | transMap[*itZoomBegin].push_back(*itZoomBegin); |
---|
| 99 | transWeight[*itZoomBegin].push_back(1.0); |
---|
| 100 | } |
---|
[623] | 101 | } |
---|
[1202] | 102 | else |
---|
| 103 | { |
---|
| 104 | for (StdSize idx = 0; idx < ni; ++idx) |
---|
| 105 | { |
---|
| 106 | transMap[ibegin+idx].push_back(ibegin+idx); |
---|
| 107 | transWeight[ibegin+idx].push_back(1.0); |
---|
| 108 | } |
---|
| 109 | } |
---|
[623] | 110 | |
---|
| 111 | updateZoom(); |
---|
[1129] | 112 | // updateAxisDestinationMask(); |
---|
[623] | 113 | } |
---|
| 114 | |
---|
[624] | 115 | /*! |
---|
| 116 | After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated |
---|
| 117 | */ |
---|
[623] | 118 | void CAxisAlgorithmZoom::updateZoom() |
---|
| 119 | { |
---|
| 120 | axisDest_->global_zoom_begin = zoomBegin_; |
---|
[821] | 121 | axisDest_->global_zoom_n = zoomSize_; |
---|
[1202] | 122 | if (!zoomIndex_.empty()) |
---|
| 123 | { |
---|
| 124 | axisDest_->global_zoom_index.resize(zoomIndex_.size()); |
---|
| 125 | std::copy(zoomIndex_.begin(), zoomIndex_.end(), axisDest_->global_zoom_index.begin()); |
---|
| 126 | } |
---|
[623] | 127 | } |
---|
| 128 | |
---|
[624] | 129 | /*! |
---|
| 130 | Update mask on axis |
---|
| 131 | Because only zoomed region on axis is not masked, the remaining must be masked to make sure |
---|
| 132 | correct index be extracted |
---|
| 133 | */ |
---|
[1144] | 134 | // void CAxisAlgorithmZoom::updateAxisDestinationMask() |
---|
| 135 | // { |
---|
| 136 | // StdSize niMask = axisDest_->mask.numElements(); |
---|
| 137 | // StdSize iBeginMask = axisDest_->begin.getValue(); |
---|
| 138 | // StdSize globalIndexMask = 0; |
---|
| 139 | // TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
| 140 | // TransformationIndexMap::const_iterator ite = (transMap).end(); |
---|
| 141 | // for (StdSize idx = 0; idx < niMask; ++idx) |
---|
| 142 | // { |
---|
| 143 | // globalIndexMask = iBeginMask + idx; |
---|
| 144 | // if (transMap.find(globalIndexMask) == ite) |
---|
| 145 | // (axisDest_->mask)(idx) = false; |
---|
| 146 | // } |
---|
| 147 | // } |
---|
[623] | 148 | |
---|
| 149 | } |
---|