[644] | 1 | #ifndef __XIOS_CSpatialTransformFilter__ |
---|
| 2 | #define __XIOS_CSpatialTransformFilter__ |
---|
| 3 | |
---|
| 4 | #include "filter.hpp" |
---|
| 5 | |
---|
| 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 |
---|
| 34 | * \return the first and the last filters of the filter graph |
---|
| 35 | */ |
---|
| 36 | static std::pair<boost::shared_ptr<CSpatialTransformFilter>, boost::shared_ptr<CSpatialTransformFilter> > |
---|
[873] | 37 | buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, double defaultValue); |
---|
| 38 | |
---|
| 39 | protected: |
---|
| 40 | /*! |
---|
| 41 | Overriding this function to process transformations with auxillary inputs |
---|
| 42 | */ |
---|
| 43 | void virtual onInputReady(std::vector<CDataPacketPtr> data); |
---|
| 44 | |
---|
| 45 | protected: |
---|
| 46 | //! Default value of output pin |
---|
| 47 | double outputDefaultValue; |
---|
[644] | 48 | }; // class CSpatialTransformFilter |
---|
| 49 | |
---|
| 50 | /*! |
---|
| 51 | * A generic filter engine wrapping a grid transformation. |
---|
| 52 | */ |
---|
| 53 | class CSpatialTransformFilterEngine : public IFilterEngine |
---|
| 54 | { |
---|
| 55 | public: |
---|
| 56 | /*! |
---|
| 57 | * Returns the engine wrapping the specified grid transformation. |
---|
| 58 | * If the engine already exists it is reused, otherwise it is created. |
---|
| 59 | * |
---|
| 60 | * \param gridTransformation the grid transformation the engine will use |
---|
| 61 | * \return the engine wrapping the specified grid transformation |
---|
| 62 | */ |
---|
| 63 | static CSpatialTransformFilterEngine* get(CGridTransformation* gridTransformation); |
---|
| 64 | |
---|
| 65 | /*! |
---|
| 66 | * Applies the grid transformation to the input data and returns the result. |
---|
| 67 | * |
---|
| 68 | * \param data a vector of packets corresponding to each slot (one in this case) |
---|
[873] | 69 | * \param [in] defaultValue default value of output data |
---|
[644] | 70 | * \return the result of the grid transformation |
---|
| 71 | */ |
---|
[873] | 72 | CDataPacketPtr applyFilter(std::vector<CDataPacketPtr> data, double defaultValue = 0); |
---|
| 73 | |
---|
| 74 | /*! |
---|
| 75 | * Applies the grid transformation to the input data and returns the result. |
---|
| 76 | * |
---|
| 77 | * \param data a vector of packets corresponding to each slot (one in this case) |
---|
| 78 | * \return the result of the grid transformation |
---|
| 79 | */ |
---|
[644] | 80 | CDataPacketPtr virtual apply(std::vector<CDataPacketPtr> data); |
---|
| 81 | |
---|
[873] | 82 | |
---|
| 83 | |
---|
[644] | 84 | protected: |
---|
| 85 | /*! |
---|
| 86 | * Constructs a filter engine wrapping the specified grid transformation. |
---|
| 87 | * |
---|
| 88 | * \param gridTransformation the grid transformation the engine will use |
---|
| 89 | */ |
---|
| 90 | CSpatialTransformFilterEngine(CGridTransformation* gridTransformation); |
---|
| 91 | |
---|
| 92 | /*! |
---|
| 93 | * Applies the grid transformation to the input data and returns the result. |
---|
| 94 | * This helper function handles all the communications. |
---|
| 95 | * |
---|
| 96 | * \param dataSrc the source data |
---|
| 97 | * \param dataDest the resulting transformed data |
---|
| 98 | */ |
---|
| 99 | void apply(const CArray<double, 1>& dataSrc, CArray<double,1>& dataDest); |
---|
| 100 | |
---|
| 101 | CGridTransformation* gridTransformation; //!< The grid transformation used by the engine |
---|
| 102 | |
---|
| 103 | //! The allocated engines |
---|
| 104 | static std::map<CGridTransformation*, boost::shared_ptr<CSpatialTransformFilterEngine> > engines; |
---|
| 105 | }; // class CSpatialTransformFilterEngine |
---|
| 106 | } // namespace xios |
---|
| 107 | |
---|
| 108 | #endif //__XIOS_CSpatialTransformFilter__ |
---|