[644] | 1 | #ifndef __XIOS_CSpatialTransformFilter__ |
---|
| 2 | #define __XIOS_CSpatialTransformFilter__ |
---|
| 3 | |
---|
| 4 | #include "filter.hpp" |
---|
| 5 | namespace xios |
---|
| 6 | { |
---|
| 7 | class CGrid; |
---|
| 8 | class CGridTransformation; |
---|
| 9 | class CSpatialTransformFilterEngine; |
---|
| 10 | |
---|
| 11 | /*! |
---|
[827] | 12 | * A generic filter with multiple input slots wrapping any type of spatial transformations. |
---|
[644] | 13 | */ |
---|
| 14 | class CSpatialTransformFilter : public CFilter |
---|
| 15 | { |
---|
| 16 | public: |
---|
| 17 | /*! |
---|
| 18 | * Constructs a filter wrapping the specified spatial transformation. |
---|
| 19 | * |
---|
| 20 | * \param gc the associated garbage collector |
---|
| 21 | * \param engine the engine defining the spatial transformation |
---|
[873] | 22 | * \param outputValue default value of output pin |
---|
[827] | 23 | * \param [in] inputSlotsCount number of input, by default there is only one for field src |
---|
[644] | 24 | */ |
---|
[873] | 25 | CSpatialTransformFilter(CGarbageCollector& gc, CSpatialTransformFilterEngine* engine, double outputValue, size_t inputSlotsCount = 1); |
---|
[644] | 26 | |
---|
| 27 | /*! |
---|
| 28 | * Builds the filter graph needed to transform the specified source grid into the specified destination grid. |
---|
| 29 | * |
---|
| 30 | * \param gc the associated garbage collector |
---|
| 31 | * \param srcGrid the source grid |
---|
| 32 | * \param destGrid the destination grid |
---|
[1018] | 33 | * \param hasMissingValue whether field source has missing value |
---|
| 34 | * \param defaultValue default value |
---|
[644] | 35 | * \return the first and the last filters of the filter graph |
---|
| 36 | */ |
---|
| 37 | static std::pair<boost::shared_ptr<CSpatialTransformFilter>, boost::shared_ptr<CSpatialTransformFilter> > |
---|
[1018] | 38 | buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, bool hasMissingValue, double defaultValue); |
---|
[873] | 39 | |
---|
| 40 | protected: |
---|
| 41 | /*! |
---|
| 42 | Overriding this function to process transformations with auxillary inputs |
---|
| 43 | */ |
---|
| 44 | void virtual onInputReady(std::vector<CDataPacketPtr> data); |
---|
| 45 | |
---|
| 46 | protected: |
---|
| 47 | //! Default value of output pin |
---|
| 48 | double outputDefaultValue; |
---|
[644] | 49 | }; // class CSpatialTransformFilter |
---|
| 50 | |
---|
| 51 | /*! |
---|
| 52 | * A generic filter engine wrapping a grid transformation. |
---|
| 53 | */ |
---|
| 54 | class CSpatialTransformFilterEngine : public IFilterEngine |
---|
| 55 | { |
---|
| 56 | public: |
---|
| 57 | /*! |
---|
| 58 | * Returns the engine wrapping the specified grid transformation. |
---|
| 59 | * If the engine already exists it is reused, otherwise it is created. |
---|
| 60 | * |
---|
| 61 | * \param gridTransformation the grid transformation the engine will use |
---|
| 62 | * \return the engine wrapping the specified grid transformation |
---|
| 63 | */ |
---|
| 64 | static CSpatialTransformFilterEngine* get(CGridTransformation* gridTransformation); |
---|
| 65 | |
---|
| 66 | /*! |
---|
| 67 | * Applies the grid transformation to the input data and returns the result. |
---|
| 68 | * |
---|
| 69 | * \param data a vector of packets corresponding to each slot (one in this case) |
---|
[873] | 70 | * \param [in] defaultValue default value of output data |
---|
[644] | 71 | * \return the result of the grid transformation |
---|
| 72 | */ |
---|
[873] | 73 | CDataPacketPtr applyFilter(std::vector<CDataPacketPtr> data, double defaultValue = 0); |
---|
| 74 | |
---|
| 75 | /*! |
---|
| 76 | * Applies the grid transformation to the input data and returns the result. |
---|
| 77 | * |
---|
| 78 | * \param data a vector of packets corresponding to each slot (one in this case) |
---|
| 79 | * \return the result of the grid transformation |
---|
| 80 | */ |
---|
[644] | 81 | CDataPacketPtr virtual apply(std::vector<CDataPacketPtr> data); |
---|
| 82 | |
---|
[873] | 83 | |
---|
| 84 | |
---|
[644] | 85 | protected: |
---|
| 86 | /*! |
---|
| 87 | * Constructs a filter engine wrapping the specified grid transformation. |
---|
| 88 | * |
---|
| 89 | * \param gridTransformation the grid transformation the engine will use |
---|
| 90 | */ |
---|
| 91 | CSpatialTransformFilterEngine(CGridTransformation* gridTransformation); |
---|
| 92 | |
---|
| 93 | /*! |
---|
| 94 | * Applies the grid transformation to the input data and returns the result. |
---|
| 95 | * This helper function handles all the communications. |
---|
| 96 | * |
---|
| 97 | * \param dataSrc the source data |
---|
| 98 | * \param dataDest the resulting transformed data |
---|
| 99 | */ |
---|
| 100 | void apply(const CArray<double, 1>& dataSrc, CArray<double,1>& dataDest); |
---|
| 101 | |
---|
| 102 | CGridTransformation* gridTransformation; //!< The grid transformation used by the engine |
---|
| 103 | |
---|
| 104 | //! The allocated engines |
---|
[1134] | 105 | //static std::map<CGridTransformation*, boost::shared_ptr<CSpatialTransformFilterEngine> > engines; |
---|
| 106 | static std::map<CGridTransformation*, boost::shared_ptr<CSpatialTransformFilterEngine> > *engines_ptr; |
---|
[1334] | 107 | #pragma omp threadprivate(engines_ptr) |
---|
[644] | 108 | }; // class CSpatialTransformFilterEngine |
---|
| 109 | } // namespace xios |
---|
| 110 | |
---|
| 111 | #endif //__XIOS_CSpatialTransformFilter__ |
---|