FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
FragmentID.hpp
1#ifndef __FIBER_FIELD_FRAGMENTID_HPP
2#define __FIBER_FIELD_FRAGMENTID_HPP
3
4#include "FieldAPI.h"
5#include <memcore/Interface.hpp>
6#include <string>
7#include "CreativeArray.hpp"
8
9namespace Fiber
10{
16 using MemCore::NullPtr;
17 using std::string;
18 using std::map;
19
20class FIELD_API FragmentIDCollection;
21
22typedef WeakPtr<FragmentIDCollection, FragmentIDCollection> FragmentIDCollectionWeakPtr;
23
24using FragmentIndex_t = unsigned;
25
26
41class FIELD_API FragmentID : public ReferenceBase<FragmentID>, public Intercube
42{
43 string name;
44
45 FragmentIDCollectionWeakPtr myFragmentIDCollection;
46 FragmentIndex_t ID;
47
48 friend class FragmentIDCollection;
49
50protected:
53
54public:
55
57 explicit FragmentID(const string&Name);
58
60 FragmentID(const string&Name,
61 FragmentIndex_t ID,
63
65 const string&Name() const
66 {
67 return name;
68 }
69
70static string Name(const RefPtr<FragmentID>&fid, const string&UnfragmentedName = "")
71 {
72 if (fid)
73 return fid->Name();
74
75 return UnfragmentedName;
76 }
77
78static string getName(const RefPtr<FragmentID>&fid, const string&UnfragmentedName = "")
79 {
80 return Name(fid, UnfragmentedName);
81 }
82
83 FragmentIndex_t getNumericalID() const
84 {
85 return ID;
86 }
87
88 const FragmentIDCollectionWeakPtr&getFragmentIDCollection() const
89 {
90 return myFragmentIDCollection;
91 }
92
93 string xml() const;
94};
95
96
100{
101 bool operator()(const WeakPtr<FragmentID>&A, const WeakPtr<FragmentID>&B) const
102 {
103 if (A == B) return false;
104 if (!A) return false;
105 if (!B) return true;
106
107 return A->getNumericalID() < B->getNumericalID();
108 }
109};
110
115{
116 Undefined = 0,
117 Offset = 1,
118 OverlapStart = 2,
119 OverlapEnd = 3
120};
121
125template <Dims_t Dims, FragmentProperty TheProperty>
126class FragmentLocation : public Interface<FragmentLocation<Dims, TheProperty> >
127 , public MultiIndex<Dims>
128{
129protected:
131 {}
132
133public:
134
136 {
138 return *FL;
139
141 FID.addInterface( FL );
142 return *FL;
143 }
144
146 {
148 }
149
150static bool get(FragmentID&FID, MultiIndex<Dims>&Value)
151 {
153 {
154 Value = *FL;
155 return true;
156 }
157 return false;
158 }
159
160static void set(FragmentID&FID, MultiIndex<Dims>&Value)
161 {
162 make(FID) = Value;
163 }
164};
165
171template <Dims_t Dims>
179
184template <Dims_t Dims>
190
195template <Dims_t Dims>
201
206template <Dims_t Dims>
212
217template <Dims_t Dims>
222
227template <Dims_t Dims>
232
237template <Dims_t Dims>
242
243
249{
250public:
252 virtual ~FragmentIterator();
253
255 virtual bool apply(const RefPtr<FragmentID>&, const RefPtr<CreativeArrayBase>&) = 0;
256};
257
258template <class T>
260{
261 T myFunctor;
262
264 : myFunctor(theFunctor)
265 {}
266
268 {
269 return myFunctor(Fid, CAB);
270 }
271};
272
273typedef FragmentIterator FieldFragmentIterator;
274
275
276
277template<>
278inline std::string element_to_string(const RefPtr<FragmentID>&fID)
279{
280 return "[\"" + FragmentID::Name(fID) + "\"]";
281}
282
283template<>
284inline std::string element_to_string(const std::vector<RefPtr<FragmentID>>&fIDs)
285{
286std::string retval = "{(" + std::to_string(fIDs.size()) + ") ";
287
288 if (fIDs.size()>0)
289 retval += element_to_string(fIDs[0]);
290
291 for(size_t i = 1; i<fIDs.size(); i++)
292 {
293 retval += ", " + element_to_string(fIDs[i]);
294 }
295
296 return retval + " }";
297}
298
299/*
300template<>
301inline std::string element_to_string(const std::vector<RefPtr<FragmentID>>&FIDs)
302{
303string retval = "{(" + std::to_string(FIDs.size()) + ") ";
304
305 if (FIDs.size()>0)
306 retval += "\"" + FragmentID::Name(FIDs[0]) + "\"";
307
308 for(size_t i = 1; i<FIDs.size(); i++)
309 {
310 retval += ", \"" + FragmentID::Name(FIDs[i]) + "\"";
311 }
312
313 return retval + " }";
314}
315*/
316
317
318} /* namespace Fiber */
319
320#endif /* __FIBER_FIELD__FRAGMENTID_HPP */
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
A collection of fragment identifiers with bijective mapping to an integer fragment number.
Definition FragmentIDCollection.hpp:19
Identification information about a field's fragment.
Definition FragmentID.hpp:42
bool getFragmentOverlapEnd(FragmentID &FID, MultiIndex< Dims > &Value)
Get the overlap end property of a fragment ID.
Definition FragmentID.hpp:238
bool getFragmentOverlapStart(FragmentID &FID, MultiIndex< Dims > &Value)
Get the overlap start property of a fragment ID.
Definition FragmentID.hpp:228
MultiIndex< Dims > & setFragmentOffset(FragmentID &FID, const MultiIndex< Dims > &Offset)
Setting the offset property of a fragment ID.
Definition FragmentID.hpp:207
void setFragmentOverlapEnd(FragmentID &FID, const MultiIndex< Dims > &OverlapEnd)
Set the overlap end property of a fragment ID.
Definition FragmentID.hpp:196
bool getFragmentOffset(FragmentID &FID, MultiIndex< Dims > &Offset)
Get the offset property of a fragment ID.
Definition FragmentID.hpp:218
void setFragmentOverlap(FragmentID &FID, const MultiIndex< Dims > &OverlapStart, const MultiIndex< Dims > &OverlapEnd)
Setting the overlap property of a fragment ID, also known as the size of a field fragment's ghost zon...
Definition FragmentID.hpp:172
void setFragmentOverlapStart(FragmentID &FID, const MultiIndex< Dims > &OverlapStart)
Get the overlap start property of a fragment ID.
Definition FragmentID.hpp:185
const string & Name() const
Text ID of the fragment.
Definition FragmentID.hpp:65
Base class for iterators over the fragments of a field.
Definition FragmentID.hpp:249
virtual bool apply(const RefPtr< FragmentID > &, const RefPtr< CreativeArrayBase > &)=0
Iteration callback function.
Definition FragmentID.hpp:128
A recursively defined multidimensional index.
Definition MultiIndex.hpp:331
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
FragmentProperty
Predefined multidimensional properties on fragments.
Definition FragmentID.hpp:115
std::nullptr_t NullPtr
string to_string(const Eagle::FixedArray< ElementType, N > &A, const char *OpenBrace="{", const char *CloseBrace="}", const char *Separator=",")
Definition FragmentID.hpp:100
Definition FragmentID.hpp:260
bool apply(const RefPtr< FragmentID > &Fid, const RefPtr< CreativeArrayBase > &CAB)
Iteration callback function.
Definition FragmentID.hpp:267