FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
NamedField.hpp
1#ifndef FISH_BONE_NAMEDFIELD_HPP
2#define FISH_BONE_NAMEDFIELD_HPP
3
4#include <bone/GridOperatorObject.hpp>
5#include <bone/FishField.hpp>
6#include <bone/FieldObject.hpp>
7#include <shrimp/VObjectStatus.hpp>
8
9namespace Fiber
10{
11
12#if 0
13
14template <size_t N>
15struct ConstString
16{
17 char buf[N + 1];
18
19 constexpr ConstString(const ConstString&CS)
20 {
21 for (size_t i = 0; i != N; ++i)
22 buf[i] = CS.buf[i];
23 }
24
25 constexpr ConstString(char const* s)
26 {
27 for (size_t i = 0; i != N; ++i)
28 buf[i] = s[i];
29 }
30
31 std::string str() const
32 {
33 return std::string(buf,N);
34 }
35};
36
37template<unsigned N>
38ConstString(char const (&)[N]) -> ConstString<N - 1>;
39
40#else
41
42using ConstString = const char*;
43
44static inline string mystr(ConstString s)
45{
46 return string(s);
47}
48
49#endif
50
51template <ConstString FieldName>
52struct NamedField : public GridOperatorObject<VObject>
53 , public StatusIndicator
54{
57
60
61
63 NamedField(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
64 : GridOperatorObject<VObject>(name, p, VP)
66 , theField(this, "field", {} )
67 , theFieldName(this, "fieldname", FieldName )
68 {}
69
72 {}
73
74static bool hasDesiredField(const RefPtr<Skeleton>&theSkeleton)
75 {
76 bool SadResult = true;
77 if (!theSkeleton) return SadResult;
78
79 theSkeleton->iterate_fields( [&SadResult]
80 (const Representer&theRepresenter, const Representation&R,
81 const FieldID&theFieldID, const Field&theField)
82 {
83 if (theFieldID.Name() == FieldName)
84 {
85 SadResult = false;
86 return false;
87 }
88 return true;
89 }
90 );
91
92 return not SadResult;
93 }
94
101 bool update(VRequest&Context, double precision) override
102 {
105
106 RefPtr<Grid> G = iG;
107 if (!G)
108 {
110 theField << Context << FS;
111 return setStatusError(Context, "No Grid.");
112 }
113
115 if (!theSkeleton)
116 {
118 theField << Context << FS;
119 return setStatusError(Context, "No Vertices on this Grid.");
120 }
121
122 if (!hasDesiredField(theSkeleton) )
123 {
124 return setStatusError(Context, "No such field on this Grid.");
125 }
126
128 FS.selectField( FieldName );
129 FS.mySkeletonID = *theSkeleton;
130 theField << Context << FS;
131
132 return setStatusInfo(Context, "Field [" + mystr(FieldName) + "] found on this Grid.");
133 }
134
135
136static bool HasFields(const WeakPtr<VCreatorBase>&VB, const RefPtr<VObject>&vobj, const Fiber::TypeList_t&AcceptedFields)
137 {
138 if (!vobj) return false;
139
141 {
142 bool HappyResult = false;
143
144 bool apply(const type_info&Type, const RefPtr<VSlot>&slot) override
145 {
146 GridSelector GS;
147 if (slot->getValue( GS, NullPtr() ) )
148 {
149 Info<Skeleton> iS = GS.getRefinementLevel(0.0, 0,0);
150
151 HappyResult = hasDesiredField(iS.getSkeleton());
152
153 return false;
154 }
155
156 return true;
157 }
158 } VOut;
159
160 vobj->iterateOutputs(VOut, typeid(GridSelector) );
161
162 return VOut.HappyResult ;
163 }
164};
165
166
167} // namespace Fiber
168
169#endif // FISH_BONE_NAMEDFIELD_HPP
_Expr< _ValFunClos< _ValArray, _Tp >, _Tp > apply(_Tp __func(_Tp)) const
basic_string< char > string
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Identifier for Fields within a Grid.
Definition FieldID.hpp:53
An internal class that stores a couple of textual names.
Definition FieldSelector.hpp:18
A Field is a collection of CreativeArrayBase reference pointers which are accessed via FragmentID obj...
Definition Field.hpp:245
Context information to select a grid from within a bundle.
Definition GridSelector.hpp:26
Info< Skeleton > getRefinementLevel(double time, int Level, int IndexDepth, const BundlePtr &SpaceTime=BundlePtr(NullPtr()))
Retrieve a skeleton for the given refinement level for the current time.
Definition GridSelector.cpp:14
const T & getValue(index_t i) const
Get the value, readonly.
Definition vector/Iterator.hpp:718
A Representation is a set of Field objects, each of them accessed via some FieldID identifier.
Definition Representation.hpp:101
RefPtr< Skeleton > findVertices(int TotalRefinement=-1) const
Find the Skeleton describing the Vertices on this Grid.
Definition SkeletonMap.cpp:285
constexpr std::basic_string< CHAR > str(const CHAR *text)
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
std::nullptr_t NullPtr
Definition fs/init.hpp:20
The information as returned by a query for Grids.
Definition GridInfo.hpp:21
Definition NamedField.hpp:54
VOutput< string > theFieldName
Also output: the name of the Field.
Definition NamedField.hpp:59
~NamedField()
Destructor.
Definition NamedField.hpp:71
NamedField(const string &name, int p, const RefPtr< VCreationPreferences > &VP)
Constructor.
Definition NamedField.hpp:63
bool update(VRequest &Context, double precision) override
Implementation of the virtual update function; inspects the input Grid object for possible fields,...
Definition NamedField.hpp:101
VOutput< Fiber::Field > theField
The output: a field.
Definition NamedField.hpp:56
A set of types.
Definition FiberType.hpp:213
virtual GridSelector getGridSelector(const RefPtr< ValuePool > &VP) const
Provide the current Grid selector, which usually would be taken from the intrinsic TypedSlot,...
Fiber::Bundle::GridInfo_t findMostRecentGrid(GridSelector &GS, const RefPtr< ValuePool > &VP, const Fiber::BundlePtr &SpaceTime=Fiber::BundlePtr(NullPtr())) const
This is a convenience function to find the most recent grid for the current time ( Fish<Slice>() or v...
Convenience class for objects operating on Grid objects.
Definition GridOperatorObject.hpp:23
bool setStatusInfo(const RefPtr< ValuePool > &Context, const string &what) const
bool setStatusError(const RefPtr< ValuePool > &Context, const string &what, bool AnnouncePublic=false) const