[644] | 1 | #ifndef __XIOS_CSpatialTransformFilter__ |
---|
| 2 | #define __XIOS_CSpatialTransformFilter__ |
---|
| 3 | |
---|
| 4 | #include "filter.hpp" |
---|
[1460] | 5 | |
---|
[644] | 6 | namespace xios |
---|
| 7 | { |
---|
| 8 | class CGrid; |
---|
| 9 | class CGridTransformation; |
---|
| 10 | class CSpatialTransformFilterEngine; |
---|
| 11 | |
---|
| 12 | /*! |
---|
[827] | 13 | * A generic filter with multiple input slots wrapping any type of spatial transformations. |
---|
[644] | 14 | */ |
---|
| 15 | class CSpatialTransformFilter : public CFilter |
---|
| 16 | { |
---|
| 17 | public: |
---|
| 18 | /*! |
---|
| 19 | * Constructs a filter wrapping the specified spatial transformation. |
---|
| 20 | * |
---|
| 21 | * \param gc the associated garbage collector |
---|
| 22 | * \param engine the engine defining the spatial transformation |
---|
[873] | 23 | * \param outputValue default value of output pin |
---|
[827] | 24 | * \param [in] inputSlotsCount number of input, by default there is only one for field src |
---|
[644] | 25 | */ |
---|
[873] | 26 | CSpatialTransformFilter(CGarbageCollector& gc, CSpatialTransformFilterEngine* engine, double outputValue, size_t inputSlotsCount = 1); |
---|
[644] | 27 | |
---|
| 28 | /*! |
---|
| 29 | * Builds the filter graph needed to transform the specified source grid into the specified destination grid. |
---|
| 30 | * |
---|
| 31 | * \param gc the associated garbage collector |
---|
| 32 | * \param srcGrid the source grid |
---|
| 33 | * \param destGrid the destination grid |
---|
[1018] | 34 | * \param hasMissingValue whether field source has missing value |
---|
| 35 | * \param defaultValue default value |
---|
[644] | 36 | * \return the first and the last filters of the filter graph |
---|
| 37 | */ |
---|
[1545] | 38 | static std::pair<std::shared_ptr<CSpatialTransformFilter>, std::shared_ptr<CSpatialTransformFilter> > |
---|
[1018] | 39 | buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, bool hasMissingValue, double defaultValue); |
---|
[873] | 40 | |
---|
| 41 | protected: |
---|
| 42 | /*! |
---|
| 43 | Overriding this function to process transformations with auxillary inputs |
---|
| 44 | */ |
---|
| 45 | void virtual onInputReady(std::vector<CDataPacketPtr> data); |
---|
| 46 | |
---|
| 47 | protected: |
---|
| 48 | //! Default value of output pin |
---|
| 49 | double outputDefaultValue; |
---|
[644] | 50 | }; // class CSpatialTransformFilter |
---|
| 51 | |
---|
[1460] | 52 | |
---|
| 53 | /*! |
---|
| 54 | * A specific spatial filter for the temporal_splitting transformation scalar -> axis. An incoming flux will be stored in an aditional dimension given by the destination axis. |
---|
| 55 | * At each flux received, the storing index (record) is increased. When it reach the size of the axis (nrecords) a new flux is generated and the record is reset to 0 |
---|
| 56 | */ |
---|
| 57 | |
---|
| 58 | class CSpatialTemporalFilter : public CSpatialTransformFilter |
---|
| 59 | { |
---|
| 60 | public: |
---|
| 61 | /*! |
---|
| 62 | * Constructs a filter wrapping the specified spatial transformation. |
---|
| 63 | * |
---|
| 64 | * \param gc the associated garbage collector |
---|
| 65 | * \param engine the engine defining the spatial transformation |
---|
| 66 | * \param [in] gridTransformation the associated transformations |
---|
| 67 | * \param outputValue default value of output pin |
---|
| 68 | * \param [in] inputSlotsCount number of input, by default there is only one for field src |
---|
| 69 | */ |
---|
| 70 | CSpatialTemporalFilter(CGarbageCollector& gc, CSpatialTransformFilterEngine* engine, CGridTransformation* gridTransformation, double outputValue, size_t inputSlotsCount = 1); |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | protected: |
---|
| 74 | /*! |
---|
| 75 | Overriding this function to process transformations with auxillary inputs |
---|
| 76 | */ |
---|
| 77 | void virtual onInputReady(std::vector<CDataPacketPtr> data); |
---|
| 78 | //! Current record in the filter |
---|
| 79 | int record ; |
---|
| 80 | //! Maximum number of records |
---|
| 81 | int nrecords; |
---|
| 82 | //! Temporary storage for output flux |
---|
| 83 | CArray<double, 1> tmpData; |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | }; // class CSpatialTemporalFilter |
---|
| 87 | |
---|
| 88 | |
---|
[644] | 89 | /*! |
---|
| 90 | * A generic filter engine wrapping a grid transformation. |
---|
| 91 | */ |
---|
| 92 | class CSpatialTransformFilterEngine : public IFilterEngine |
---|
| 93 | { |
---|
| 94 | public: |
---|
| 95 | /*! |
---|
| 96 | * Returns the engine wrapping the specified grid transformation. |
---|
| 97 | * If the engine already exists it is reused, otherwise it is created. |
---|
| 98 | * |
---|
| 99 | * \param gridTransformation the grid transformation the engine will use |
---|
| 100 | * \return the engine wrapping the specified grid transformation |
---|
| 101 | */ |
---|
| 102 | static CSpatialTransformFilterEngine* get(CGridTransformation* gridTransformation); |
---|
| 103 | |
---|
| 104 | /*! |
---|
| 105 | * Applies the grid transformation to the input data and returns the result. |
---|
| 106 | * |
---|
| 107 | * \param data a vector of packets corresponding to each slot (one in this case) |
---|
[873] | 108 | * \param [in] defaultValue default value of output data |
---|
[644] | 109 | * \return the result of the grid transformation |
---|
| 110 | */ |
---|
[873] | 111 | CDataPacketPtr applyFilter(std::vector<CDataPacketPtr> data, double defaultValue = 0); |
---|
| 112 | |
---|
| 113 | /*! |
---|
| 114 | * Applies the grid transformation to the input data and returns the result. |
---|
| 115 | * |
---|
| 116 | * \param data a vector of packets corresponding to each slot (one in this case) |
---|
| 117 | * \return the result of the grid transformation |
---|
| 118 | */ |
---|
[644] | 119 | CDataPacketPtr virtual apply(std::vector<CDataPacketPtr> data); |
---|
| 120 | |
---|
[873] | 121 | |
---|
| 122 | |
---|
[644] | 123 | protected: |
---|
| 124 | /*! |
---|
| 125 | * Constructs a filter engine wrapping the specified grid transformation. |
---|
| 126 | * |
---|
| 127 | * \param gridTransformation the grid transformation the engine will use |
---|
| 128 | */ |
---|
| 129 | CSpatialTransformFilterEngine(CGridTransformation* gridTransformation); |
---|
| 130 | |
---|
| 131 | /*! |
---|
| 132 | * Applies the grid transformation to the input data and returns the result. |
---|
| 133 | * This helper function handles all the communications. |
---|
| 134 | * |
---|
| 135 | * \param dataSrc the source data |
---|
| 136 | * \param dataDest the resulting transformed data |
---|
| 137 | */ |
---|
| 138 | void apply(const CArray<double, 1>& dataSrc, CArray<double,1>& dataDest); |
---|
| 139 | |
---|
| 140 | CGridTransformation* gridTransformation; //!< The grid transformation used by the engine |
---|
| 141 | |
---|
| 142 | //! The allocated engines |
---|
[1642] | 143 | static std::map<CGridTransformation*, std::shared_ptr<CSpatialTransformFilterEngine> > engines; |
---|
[644] | 144 | }; // class CSpatialTransformFilterEngine |
---|
| 145 | } // namespace xios |
---|
| 146 | |
---|
| 147 | #endif //__XIOS_CSpatialTransformFilter__ |
---|