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