source: XIOS/trunk/src/filter/spatial_transform_filter.hpp @ 1704

Last change on this file since 1704 was 1704, checked in by yushan, 5 years ago

Introducing the new graph functionality. Attribute build_workflow_graph=.TRUE. is used in the field definition section in the xml file to enable the workflow graph of the field and other fields referecing to it. A more detailed document will be available soon on the graph fuctionality.

File size: 5.9 KB
Line 
1#ifndef __XIOS_CSpatialTransformFilter__
2#define __XIOS_CSpatialTransformFilter__
3
4#include "filter.hpp"
5#include "field.hpp"
6
7namespace xios
8{
9  class CGrid;
10  class CGridTransformation;
11  class CSpatialTransformFilterEngine;
12
13  class CField;
14
15  /*!
16   * A generic filter with multiple input slots wrapping any type of spatial transformations.
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
26       * \param outputValue default value of output pin
27       * \param [in] inputSlotsCount number of input, by default there is only one for field src
28       */
29      CSpatialTransformFilter(CGarbageCollector& gc, CSpatialTransformFilterEngine* engine,
30                              double outputValue, size_t inputSlotsCount = 1);
31
32      inline StdString GetName(void) {return StdString("Spatial transform filter");};
33
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
40       * \param hasMissingValue whether field source has missing value
41       * \param defaultValue default value
42       * \return the first and the last filters of the filter graph
43       */
44      static std::pair<std::shared_ptr<CSpatialTransformFilter>, std::shared_ptr<CSpatialTransformFilter> >
45      buildFilterGraph(CGarbageCollector& gc, CGrid* srcGrid, CGrid* destGrid, bool hasMissingValue, double defaultValue);
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;
56  }; // class CSpatialTransformFilter
57
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
95  /*!
96   * A generic filter engine wrapping a grid transformation.
97   */
98  class CSpatialTransformFilterEngine : public IFilterEngine
99  {
100    public:
101
102      int filterID;
103      int tag;
104      CField *field;
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)
118       * \param [in] defaultValue default value of output data
119       * \return the result of the grid transformation
120       */
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);
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       */
130      CDataPacketPtr virtual apply(std::vector<CDataPacketPtr> data);
131
132
133
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       */
149      void apply(const CArray<double, 1>& dataSrc, CArray<double,1>& dataDest, int filterID=-1);
150
151      CGridTransformation* gridTransformation; //!< The grid transformation used by the engine
152
153      //! The allocated engines
154      static std::map<CGridTransformation*, std::shared_ptr<CSpatialTransformFilterEngine> > engines;
155  }; // class CSpatialTransformFilterEngine
156} // namespace xios
157
158#endif //__XIOS_CSpatialTransformFilter__
Note: See TracBrowser for help on using the repository browser.