FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
ComputationalField.hpp
1#ifndef __FIBER_FIELD_COMPUTATIONAL_FIELD_HPP
2#define __FIBER_FIELD_COMPUTATIONAL_FIELD_HPP
3
4#include "Field.hpp"
5#include "OnDemandCreator.hpp"
6
7namespace Fiber
8{
9
65template <class FieldOperator>
66class ComputationalField : public Field, public FieldOperator //, public FragmentIterator
67{
68public:
74
80 ComputationalField(const FieldOperator&FO, const RefPtr<Field>&InputField,
82 : Field( InputField->getFragmentIDCollection() )
83 , FieldOperator(FO)
85 {
86 if (InputField)
87 {
88 this->createFieldFragments(*InputField);
89 }
90 }
91
97 ComputationalField(const FieldOperator&FO, const Field&InputField,
99 : Field( InputField.getFragmentIDCollection() )
100 , FieldOperator(FO)
102 {
103 this->createFieldFragments(InputField);
104 }
105
106 using primary_value_type = typename FieldOperator::primary_value_type;
107 using result_type = typename FieldOperator::result_type;
108
114 {
115 WeakPtr<ComputationalField> myComputationalField;
116 RefPtr<FragmentID> myFragmentID;
117 RefPtr<CreativeArrayBase> myInputFieldFragment;
118
123 : myComputationalField( theComputationalField )
124 , myFragmentID ( theFragmentID )
125 , myInputFieldFragment( theInputFieldFragment )
126 {}
127 };
128
129
135 template <Dims_t Dims>
137 {
140
141 RefPtr<ResultArray_t> result_storage;
142
144 {
145 assert( Params.myComputationalField );
146 assert( Params.myInputFieldFragment );
147
148 // HERE iterate over procedural arrays
150 if (RefPtr<PrimaryArray_t> InputData = Params.myInputFieldFragment->create() )
151 {
152 RefPtr<ResultArray_t> OutputData = new ResultArray_t( InputData->Size(), C );
153
154 if (Params.myComputationalField->computeFragment( *OutputData, *InputData, Params.myFragmentID) )
155 {
156 result_storage = OutputData;
157 }
158 }
159 }
160
161 RefPtr<ResultArray_t> result() const
162 {
163 return result_storage;
164 }
165 };
166
167
177 {
178 if (!CAB) return true; // or false? stop iteration?
179
180 if (fid)
181 {
182 if ( getFragmentIDCollection() and getFragmentIDCollection() != fid->getFragmentIDCollection() )
183 Verbose(0) << " ComputationalField::setCreator() - MISMATCH in fragment ID collection! ";
184
185 Assert( getFragmentIDCollection() == fid->getFragmentIDCollection() );
186 }
187
188
190 {
191 const MemArrayProperties&MAP = *pMAP;
192 if (MAP.myElementType() != typeid(primary_value_type) )
193 {
194 // input field does not have appropriate type
195 // thus not even setting up creator
196 return false;
197 }
198
199 if (pMAP->rank==3)
200 {
203
204 return true;
205 }
206 else if (pMAP->rank==2)
207 {
210
211 return true;
212 }
213 else if (pMAP->rank==1)
214 {
217
218 return true;
219 }
220 else
221 {
222 Assert(0 && "Computational Field attempted on field with unsupported mem array rank on its creators");
223 return false;
224 }
225 }
226
227 Assert(0 && "Computational Field attempted on field without mem array properties on its creators");
228 return false;
229 }
230
246// const MemCore::WeakPtr<FragmentSelector>&FS = NullPtr() )
247 {
248 Assert( getFragmentIDCollection() == SourceData.getFragmentIDCollection() );
249
250 return SourceData.iterate( [this](const RefPtr<FragmentID>&FragID, const RefPtr<CreativeArrayBase>&CAB)
251 {
252 return apply(FragID, CAB);
253 }
254 );
255
256// return SourceData.iterate(*this, FS);
257 }
258};
259
260
265template <class FieldOperator>
272
273
278template <class FieldOperator>
280 const Field&InputField,
282{
283 return new ComputationalField<FieldOperator>(FO, InputField, theCache);
284}
285
286} // namespace Fiber
287
288
289#endif // __FIBER_FIELD_COMPUTATIONAL_FIELD_HPP
A field which contains computational operations that are executed on demand per fragment.
Definition ComputationalField.hpp:67
ComputationalField(const FieldOperator &FO, const Field &InputField, const MemCore::RefPtr< MemCore::Cache > &theCache=MemCore::Cache::MemCache())
The Constructor wants an instance of the associated field operator and the primary input field.
Definition ComputationalField.hpp:97
MemCore::RefPtr< MemCore::Cache > myCache
Reference to the cache object managing the memory occupied by the resulting data.
Definition ComputationalField.hpp:73
ComputationalField(const FieldOperator &FO, const RefPtr< Field > &InputField, const MemCore::RefPtr< MemCore::Cache > &theCache=MemCore::Cache::MemCache())
The Constructor wants an instance of the associated field operator and the primary input field.
Definition ComputationalField.hpp:80
int createFieldFragments(const Field &SourceData)
Create the fragments of this field, usually not to be called explicitly.
Definition ComputationalField.hpp:245
bool apply(const RefPtr< FragmentID > &fid, const RefPtr< CreativeArrayBase > &CAB)
The fragment iteration callback function.
Definition ComputationalField.hpp:176
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
A Field is a collection of CreativeArrayBase reference pointers which are accessed via FragmentID obj...
Definition Field.hpp:245
const RefPtr< CreativeArrayBase > & setCreator(const RefPtr< CreativeArrayBase > &FFC, const RefPtr< FragmentID > &=nullptr)
Sets the creator for an unfragmented field.
Definition Field.cpp:433
Interface class to provide information about multidimensional arrays without need to create the data ...
Definition MemArrayProperties.hpp:28
A Creator object that allows to create data on demand, when they are used and accessed.
Definition OnDemandCreator.hpp:65
static RefPtr< Cache, CacheBase > & MemCache()
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
ComputationalField< FieldOperator > * newComputationalField(const FieldOperator &FO, const RefPtr< Field > &InputField, const MemCore::RefPtr< MemCore::Cache > &theCache=MemCore::Cache::MemCache())
A convenience template function to construct a computational field (class ComputationalField) from an...
Definition ComputationalField.hpp:266
Internal helper class to pass parameters from the computational field class to the on-demand creators...
Definition ComputationalField.hpp:114
Internal helper class which calls the computeFragment() member function of the associated FieldOperat...
Definition ComputationalField.hpp:137