[1985] | 1 | /*! |
---|
| 2 | \file axis_algorithm_zoom.cpp |
---|
| 3 | \brief Algorithm for zooming an axis. |
---|
| 4 | */ |
---|
| 5 | #include "axis_algorithm_zoom.hpp" |
---|
| 6 | #include "axis.hpp" |
---|
| 7 | #include "grid.hpp" |
---|
| 8 | #include "grid_transformation_factory_impl.hpp" |
---|
| 9 | #include "zoom_axis.hpp" |
---|
| 10 | |
---|
| 11 | namespace xios { |
---|
[2270] | 12 | shared_ptr<CGenericAlgorithmTransformation> CAxisAlgorithmZoom::create(bool isSource, CGrid* gridDst, CGrid* gridSrc, |
---|
[1985] | 13 | CTransformation<CAxis>* transformation, |
---|
| 14 | int elementPositionInGrid, |
---|
| 15 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
| 16 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
| 17 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
| 18 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
| 19 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
| 20 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
| 21 | TRY |
---|
| 22 | { |
---|
| 23 | std::vector<CAxis*> axisListDestP = gridDst->getAxis(); |
---|
| 24 | std::vector<CAxis*> axisListSrcP = gridSrc->getAxis(); |
---|
| 25 | |
---|
| 26 | CZoomAxis* zoomAxis = dynamic_cast<CZoomAxis*> (transformation); |
---|
| 27 | int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid]; |
---|
| 28 | int axisSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid]; |
---|
| 29 | |
---|
[2270] | 30 | return make_shared<CAxisAlgorithmZoom>(isSource, axisListDestP[axisDstIndex], axisListSrcP[axisSrcIndex], zoomAxis); |
---|
[1985] | 31 | } |
---|
| 32 | CATCH |
---|
| 33 | |
---|
| 34 | bool CAxisAlgorithmZoom::dummyRegistered_ = CAxisAlgorithmZoom::registerTrans(); |
---|
| 35 | bool CAxisAlgorithmZoom::registerTrans() |
---|
| 36 | TRY |
---|
| 37 | { |
---|
| 38 | return CGridTransformationFactory<CAxis>::registerTransformation(TRANS_ZOOM_AXIS, create); |
---|
| 39 | } |
---|
| 40 | CATCH |
---|
| 41 | |
---|
[1988] | 42 | CAxisAlgorithmZoom::CAxisAlgorithmZoom(bool isSource, CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis) |
---|
[1998] | 43 | : CAlgorithmTransformationTransfer(isSource), axisDest_(axisDestination), axisSrc_(axisSource) |
---|
[1985] | 44 | TRY |
---|
| 45 | { |
---|
| 46 | zoomAxis->checkValid(axisSource); |
---|
| 47 | zoomBegin_ = zoomAxis->begin.getValue(); |
---|
| 48 | zoomN_ = zoomAxis->n.getValue(); |
---|
| 49 | zoomEnd_ = zoomBegin_ + zoomN_ - 1; |
---|
| 50 | |
---|
| 51 | if (zoomN_ > axisSource->n_glo.getValue()) |
---|
| 52 | { |
---|
| 53 | ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)", |
---|
| 54 | << "Zoom size is greater than global size of source axis" |
---|
| 55 | << "Global size of source axis " <<axisSource->getId() << " is " << axisSource->n_glo.getValue() << std::endl |
---|
| 56 | << "Zoom size is " << zoomN_ ); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | int idxSrc, nDest = 0, beginDestLoc, beginDestGlo = 0 ; |
---|
| 60 | int indGloDest, indGloSrc, iSrc; |
---|
| 61 | for (int i = 0; i < axisSrc_->n.getValue(); i++) |
---|
| 62 | { |
---|
| 63 | idxSrc = axisSrc_->index(i); |
---|
| 64 | if ((idxSrc >= zoomBegin_) && (idxSrc <= zoomEnd_)) |
---|
| 65 | { |
---|
| 66 | if (nDest == 0) beginDestLoc = i; |
---|
| 67 | ++nDest; |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | beginDestGlo = beginDestLoc + axisSrc_->begin - zoomBegin_; |
---|
| 71 | axisDest_->n_glo.setValue(zoomN_); |
---|
| 72 | axisDest_->n.setValue(nDest); |
---|
| 73 | axisDest_->begin.setValue(beginDestGlo); |
---|
| 74 | axisDest_->index.resize(nDest); |
---|
| 75 | |
---|
| 76 | axisDest_->data_n.setValue(nDest); |
---|
| 77 | axisDest_->data_begin.setValue(0); |
---|
| 78 | axisDest_->data_index.resize(nDest); |
---|
| 79 | |
---|
| 80 | axisDest_->mask.resize(nDest); |
---|
[2482] | 81 | if (axisSrc_->hasValue()) axisDest_->value.resize(nDest); |
---|
| 82 | if (axisSrc_->hasLabel()) axisDest_->label.resize(nDest); |
---|
| 83 | if (axisSrc_->hasBounds()) axisDest_->bounds.resize(2,nDest); |
---|
[1985] | 84 | |
---|
[1998] | 85 | auto& transMap = this->transformationMapping_; |
---|
[1985] | 86 | |
---|
| 87 | for (int iDest = 0; iDest < nDest; iDest++) |
---|
| 88 | { |
---|
| 89 | iSrc = iDest + beginDestLoc; |
---|
| 90 | axisDest_->index(iDest) = iDest + beginDestGlo; |
---|
| 91 | axisDest_->data_index(iDest) = axisSrc_->data_index(iSrc) - beginDestLoc; |
---|
| 92 | axisDest_->mask(iDest) = axisSrc_->mask(iSrc); |
---|
| 93 | |
---|
[2482] | 94 | if (axisSrc_->hasValue()) |
---|
[1985] | 95 | axisDest_->value(iDest) = axisSrc_->value(iSrc); |
---|
[2482] | 96 | if (axisSrc_->hasLabel()) |
---|
[1985] | 97 | axisDest_->label(iDest) = axisSrc_->label(iSrc); |
---|
[2482] | 98 | if (axisSrc_->hasBounds()) |
---|
[1985] | 99 | { |
---|
| 100 | axisDest_->bounds(0,iDest) = axisSrc_->bounds(0,iSrc); |
---|
| 101 | axisDest_->bounds(1,iDest) = axisSrc_->bounds(1,iSrc); |
---|
| 102 | } |
---|
| 103 | indGloDest = axisDest_->index(iDest); |
---|
| 104 | indGloSrc = axisSrc_->index(iSrc); |
---|
[1998] | 105 | transMap[indGloDest]=indGloSrc; |
---|
[1985] | 106 | |
---|
| 107 | } |
---|
[1998] | 108 | |
---|
| 109 | axisDestination->checkAttributes() ; |
---|
| 110 | |
---|
| 111 | this->computeAlgorithm(axisSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ; |
---|
[1985] | 112 | } |
---|
| 113 | CATCH |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | } |
---|