FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
Representation.hpp
1#ifndef __FIBER_GRID_REPRESENTATION_HPP
2#define __FIBER_GRID_REPRESENTATION_HPP "Created 27.02.2001 21:42:27 by werner"
3
4#include "GridAPI.h"
5#include <fiber/field/Field.hpp>
6#include "FieldID.hpp"
7#include <memcore/TypeInfo.hpp>
8#include <set>
9#include <list>
10
11#include "FiberSpace.hpp"
12#include <fiber/field/BaseSpace.hpp>
13#include "RepresentationMap.hpp"
14
15namespace Fiber
16{
17 using MemCore::WeakPtr;
18 using MemCore::NullPtr;
19 using std::set;
20 using std::list;
21
22constexpr const char FIBER_POSITIONS[] = "Positions";
23
24
25class GRID_API Representation;
26
27#if 0
28#define FIBER_MAP_TO_MAP
29#endif
30
37{
38 Representation& myRepresentation;
39 const string myFieldname;
40 RefPtr<FragmentIDCollection> myFragmentIDCollection;
41 RefPtr<MemBase> myFragmentTopology;
42
43 RefPtr<Field>&FieldPtr;
44
45 FieldProxy(const FieldProxy&FP);
46
49 const string &theFieldname,
53
55
58
61
62 RefPtr<Field>&make() const;
63
65 operator RefPtr<Field>&() const;
66
68 const RefPtr<Field>&operator->() const;
69
70
71 operator bool() const
72 {
73 return FieldPtr.valid();
74 }
75};
76
77
78
95class GRID_API Representation : public FiberMap<RefPtr<FieldID> >
96 , public Intercube
98#ifdef FIBER_MAP_TO_MAP
99 , public RepresentationMap
100#endif
101{
102public: typedef FiberMap<RefPtr<FieldID> > Base_t;
105
106#ifdef FIBER_MAP_TO_MAP
107 using RepresentationMap::operator[];
108 using RepresentationMap::makeRepresentation;
109 using RepresentationMap::operator();
110#endif
111
112 unsigned long RenameOperations = 0, RemovalOperations = 0;
113
114static constexpr unsigned long MaxOperations = -22U;
115
118
121
123 void operator=(const Representation&) = delete;
124
127
128 void extremeUnction() override;
129
141 RefPtr<FieldID> makeFieldID(const string&name);
142
150 RefPtr<FieldID> findFieldID(const string&name) const;
151
152 bool removeField(const string&name);
153 bool removeField(const RefPtr<FieldID>&FID);
154
155 RefPtr<FieldID> renameField(const string&OldName, const string&NewName);
156
163 RefPtr<FieldID> insertSharedFieldID(const Representation&R, const string&name);
164
174 RefPtr<FieldID> createSharedFieldID(Representation&Carrier, const string&name);
175
176
180 RefPtr<Field> &getField(const RefPtr<FieldID>&f);
181
185 const RefPtr<Field>&findField(const RefPtr<FieldID>&f) const;
186
190 const RefPtr<Field>&findField(const FieldID&f) const;
191
199 bool checkIfFieldSizeIsIncompatible(const RefPtr<Field>&FieldPtr);
200
201private:
202 bool AdjustAndCheckSkeletonSize(Field&P, const string&FieldName);
203
204 friend struct FieldProxy;
205
206public:
207
208 FieldProxy makeField(const WeakPtr<FieldID>&rf,
211
212 Field &makeField(const FieldID&f);
213
217 void own(Field&) const;
218
226 {
227 return makeField(f);
228 }
229
235 {
236 return makeField(f);
237 }
238
243 FieldProxy operator[](const string&name)
244 {
245 return makeField( makeFieldID(name) );
246 }
247
248#ifdef FIBER_MAP_TO_MAP
250#endif
251
257 const RefPtr<Field>&findField(const string&name) const
258 {
259 RefPtr<FieldID> fid = findFieldID(name);
260 if (!fid)
261 return Field::NullPtrField();
262
263 return findField( fid );
264 }
265
266 const RefPtr<Field>&findField(const char*name) const
267 {
268 return findField( string(name) );
269 }
270
271 template <class FieldNameContainer>
272 const RefPtr<Field>&findField(const FieldNameContainer&FieldNames) const
273 {
274 for(const auto&f : FieldNames)
275 {
276 if (const auto&F = findField(f) )
277 return F;
278 }
279 return Field::NullPtrField();
280 }
281
289 const RefPtr<Field>&operator()(const string&name) const
290 {
291 return findField( name );
292 }
293
294 const RefPtr<Field>&operator()(const char*name) const
295 {
296 return findField( name );
297 }
298
299 const RefPtr<Field>&operator()(const FieldID&fid) const
300 {
301 return findField( fid );
302 }
303
305 const RefPtr<Field>&operator()(const RefPtr<FieldID>&f) const;
306
307 template <class FieldNameContainer>
308 const RefPtr<Field>&operator()(const FieldNameContainer&FieldNames) const
309 {
310 return findField( FieldNames );
311 }
312
318 {
319 RefPtr<Field> F = findField(name);
320 if (!F)
321 return NullPtr();
322
323 return F->getCreator(f);
324 }
325
326 RefPtr<CreativeArrayBase> operator()(const string&name, const string&FragmentName)
327 {
328 RefPtr<Field> F = findField(name);
329 if (!F)
330 return NullPtr();
331
332 return F->getCreatorByName(FragmentName);
333 }
334
337 {
338 RefPtr<FieldID> PositionsName = findFieldID( FIBER_POSITIONS );
339 if (!PositionsName)
340 return Field::NullPtrField();
341
342 return findField( PositionsName );
343 }
344
347 {
348 return Positions();
349 }
350
351
352// const RefPtr<Field>&getFirstField() const;
353
363 RefPtr<SizeInterface> getSize() const;
364
369 RefPtr<SizeInterface> getFragmentSize(const RefPtr<FragmentID>&Fid) const;
370
374 bool setField(const string&Fieldname, const RefPtr<Field>&P);
375
388 bool setPositions(const RefPtr<Field>&P);
389
394 template <class Data, Dims_t Dims>
397 {
398 return setPositions(new Field(D, Size, theFragmentIDCollection));
399 }
400
405 template <class T, Dims_t N>
411
421
431
436 template <class Data, Dims_t Dims>
437 bool setField(const string&Fieldname, const Data&D, const MultiIndex<Dims>&Size,
439 {
440 return setField(Fieldname, new Field(D, Size, theFragmentIDCollection) );
441 }
442
446 template <class T, Dims_t N>
447 bool setField(const string&Fieldname, const MemCore::WeakPtr<MemArray<N, T> >&MemRefPtr,
449
450 {
451 return setField(Fieldname, new Field(MemRefPtr, theFragmentIDCollection) );
452 }
453
457 bool setField(const string&Fieldname, const MemCore::RefPtr<MemBase>&MemRefPtr,
459
460 {
461 return setField(Fieldname, new Field(MemRefPtr, theFragmentIDCollection) );
462 }
463
464
468 bool setField(const string&Fieldname, const MemCore::RefPtr<CreativeArrayBase>&CrecPtr,
470
471 {
472 return setField(Fieldname, new Field(CrecPtr, theFragmentIDCollection) );
473 }
474
475
493 [[deprecated("Use modern version with lambda functions instead.")]]
494 int iterate(FieldIterator&FI) const;
495
496 using const_iterator_t = std::function<bool(const FieldID&, const Field&)>;
502 using iterator_t = std::function<bool(const FieldID&, Field&)>;
503
504
506 int iterate_fields(const iterator_t&F) const;
507
511 int iterate_const_fields(const const_iterator_t&F) const
512 {
513 return iterate_fields(F);
514 }
515
519 int iterate(const iterator_t&F) const
520 {
521 return iterate_fields(F);
522 }
523
524
528 [[deprecated("Just use iterate().")]]
529 int iterate_m(const iterator_t&F) const
530 {
531 return iterate_fields(F);
532 }
533
534 typedef FieldIterator Iterator;
535
536 using iterate_all_t = std::function<bool(const FieldID&d, Field&F, const RefPtr<CreativeArrayBase>&CAB, const RefPtr<FragmentID>&fid)>;
537
538
557 int iterate_all(const iterate_all_t&f) const
558 {
559 return iterate( [&f](const FieldID&theFieldID, Field&theField) -> bool
560 {
561 theField.iterate( [&f,&theFieldID,&theField](const RefPtr<FragmentID>&fid,
563 {
564 return f( theFieldID, theField, CAB, fid);
565 }
566 );
567 return true;
568 }
569 );
570 }
571
572 int iterate(const iterate_all_t&f) const
573 {
574 return iterate_all(f);
575 }
576
577
578 template <class Functor>
579 [[deprecated("Use iterate_all() with functor instead")]]
580 int Iterate_all(const Functor&F) const
581 {
582/*
583 struct MyF : Iterator
584 {
585 const Functor&f;
586 MyF(const Functor&F)
587 : f(F)
588 {}
589
590 bool apply(const FieldID&theFieldID, const Field&theField) override
591 {
592 theField.iterate_fragments( [this, &theFieldID,&theField](const RefPtr<FragmentID>&fid,
593 const RefPtr<CreativeArrayBase>&CAB)
594 {
595 f( theFieldID, theField, CAB, fid);
596 return true;
597 }
598 );
599 return true;
600 }
601 }
602 mf(F);
603 return iterate(mf);
604*/
605 return iterate( [&F](const FieldID&theFieldID, const Field&theField)
606 {
607 theField.iterate( [&F,&theFieldID,&theField](const RefPtr<FragmentID>&fid,
608 const RefPtr<CreativeArrayBase>&CAB)
609 {
610 return F( theFieldID, theField, CAB, fid);
611 }
612 );
613 return true;
614 }
615 );
616 }
617
618
624 Dims_t Dims() const;
625
626 DEPRECATED("Use Dims() or getSize() instead",
627 Dims_t rank() const)
628 {
629 return Dims();
630 }
631
632
633 RefPtr<FragmentIDCollection> getFragmentIDCollection() const override;
634
638 memsize_t getMemoryUsage(memsize_t&UsedMemory, memsize_t&WantedMemory) const;
639
640
644 void Speak(int indent=0, int maxindent=-1) const;
645
647 string xml() const;
648
649 void createLinkedFields( const Representation& linked_from );
650};
651
652
657extern GRID_API
658int pullFragments(Representation&Dst, const RefPtr<FragmentID>&DstID,
661 const DynamicSize&DestSize);
662
663
664
665template <>
667{
668};
669
670
671template <class Functor>
673{
674 struct MyF : ConstIterator
675 {
676 const Functor&f;
677 MyF(const Functor&F)
678 : f(F)
679 {}
680
681 bool apply(const Representer&theRepresenter, const Representation&R) override
682 {
683 R.iterate_all( [this, &theRepresenter, &R]
684 (const FieldID&theFieldID, const Field&F,
686 {
687 f(theRepresenter,R, theFieldID, F, CAB, fid);
688 return true;
689 }
690 );
691 return true;
692 }
693 }
694 mf(F);
695 return iterate(mf);
696}
697
702template <class Functor>
703inline int operator<<=(const Representation&R, const Functor&F)
704{
705 return R.iterate(F);
706}
707
712template <class Functor>
713inline int operator<<=(const RefPtr<Representation>&R, const Functor&F)
714{
715 if (!R)
716 return 0;
717
718 return R->iterate(F);
719}
720
721
722
723} /* namespace Fiber */
724
725#endif /* __FIBER_GRID_REPRESENTATION_HPP */
strong_ordering operator(const error_code &__lhs, const error_code &__rhs) noexcept
constexpr complex< _Tp > & operator=(const _Tp &)
_Expr< _ValFunClos< _ValArray, _Tp >, _Tp > apply(_Tp __func(_Tp)) const
Base class for spaces that may be used for mapping domains to fiber spaces.
Definition BaseSpace.hpp:38
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
A class describing an n-dimensional space at runtime.
Definition field/DynamicSize.hpp:29
Base class for fields defined on some base space.
Definition FiberSpace.hpp:33
Identifier for Fields within a Grid.
Definition FieldID.hpp:53
Class for iterating over fields, in particular those contained in a Representation object.
Definition FieldID.hpp:134
A Field is a collection of CreativeArrayBase reference pointers which are accessed via FragmentID obj...
Definition Field.hpp:245
Convenience base class.
Definition FragmentIDCollection.hpp:153
Implementation of an Iterator to a sequence of elements, which might be contiguous or a projection of...
Definition vector/Iterator.hpp:525
T & operator[](index_t i) const
Access an element of the array, writeable.
Definition vector/Iterator.hpp:712
Constant Iterator base class to inspect all representations in a given RepresentationMap.
Definition RepresentationMap.hpp:124
A map that associates Representer objects with Representation instances.
Definition RepresentationMap.hpp:41
int iterate(ConstIterator &) const
Inspect all elements of this map.
Definition RepresentationMap.cpp:185
int iterate_all(const Functor &F) const
Definition Representation.hpp:672
A Representation is a set of Field objects, each of them accessed via some FieldID identifier.
Definition Representation.hpp:101
int iterate_m(const iterator_t &F) const
Functor iterator with non-constant, modifyable field.
Definition Representation.hpp:529
void operator=(const Representation &)=delete
Prevent accidental copy assignment.
int iterate(const iterator_t &F) const
Functor iterator.
Definition Representation.hpp:519
const RefPtr< Field > & operator()(const string &name) const
Operator interface to the findField function.
Definition Representation.hpp:289
FieldProxy operator[](const string &name)
Make a field reference from a string, field ID is created if not yet existent.
Definition Representation.hpp:243
const RefPtr< Field > & Positions() const
Get the positions component of this Representation object.
Definition Representation.hpp:336
int iterate(FieldIterator &FI) const
Iterate over all fields in this Representation.
Definition Representation.cpp:548
bool setField(const string &Fieldname, const MemCore::WeakPtr< MemArray< N, T > > &MemRefPtr, const RefPtr< FragmentIDCollection > &theFragmentIDCollection=nullptr)
Convenience function to set an unfragmented field direcly from a MemArray.
Definition Representation.hpp:447
bool setPositions(const MemCore::RefPtr< MemBase > &MemRefPtr, const RefPtr< FragmentIDCollection > &theFragmentIDCollection=nullptr)
Convenience function to set unfragmented positions directly from some MemBase.
Definition Representation.hpp:416
const RefPtr< Field > & findField(const string &name) const
Retrieve a field by its name; usually fields should be retrieved via their field identifier instead,...
Definition Representation.hpp:257
bool setPositions(const MemCore::RefPtr< CreativeArrayBase > &CrecRefPtr, const RefPtr< FragmentIDCollection > &theFragmentIDCollection=nullptr)
Convenience function to set unfragmented positions directly from some CreativeArrayBase.
Definition Representation.hpp:426
bool setPositions(const MemCore::WeakPtr< MemArray< N, T > > &MemRefPtr, const RefPtr< FragmentIDCollection > &theFragmentIDCollection=nullptr)
Convenience function to set unfragmented positions directly from some MemArray.
Definition Representation.hpp:406
bool setField(const string &Fieldname, const MemCore::RefPtr< CreativeArrayBase > &CrecPtr, const RefPtr< FragmentIDCollection > &theFragmentIDCollection=nullptr)
Convenience function to set an unfragmented field direcly from a CreativeArrayBase.
Definition Representation.hpp:468
std::function< bool(const FieldID &, Field &)> iterator_t
Note that an iterator_t can be implicitly cast into an const_iterator_t, thus functions taking an ite...
Definition Representation.hpp:502
FieldProxy operator[](const RefPtr< FieldID > &f)
Return reference to the internally stored Field pointer, which may be overwritten by the caller.
Definition Representation.hpp:234
Representation(const Representation &)=delete
Prevent accidental copy construction.
RefPtr< CreativeArrayBase > operator()(const string &name, const RefPtr< FragmentID > &f)
Shortcut function: Checks if a field exist, and if so, retrieves the data that are associated with a ...
Definition Representation.hpp:317
bool setField(const string &Fieldname, const MemCore::RefPtr< MemBase > &MemRefPtr, const RefPtr< FragmentIDCollection > &theFragmentIDCollection=nullptr)
Convenience function to set an unfragmented field direcly from a MemBase.
Definition Representation.hpp:457
bool setPositions(const Data &D, const MultiIndex< Dims > &Size, const RefPtr< FragmentIDCollection > &theFragmentIDCollection=nullptr)
Convenience function to set unfragmented positions directly from some data set, e....
Definition Representation.hpp:395
bool setField(const string &Fieldname, const Data &D, const MultiIndex< Dims > &Size, const RefPtr< FragmentIDCollection > &theFragmentIDCollection=nullptr)
Convenience function to set an unfragmented field direcly from some data that can be used for constuc...
Definition Representation.hpp:437
int iterate_const_fields(const const_iterator_t &F) const
Functor iterator with constant field.
Definition Representation.hpp:511
int iterate_all(const iterate_all_t &f) const
Definition Representation.hpp:557
const RefPtr< Field > & getPositions() const
Get the positions component of this Representation object.
Definition Representation.hpp:346
Field & operator[](const FieldID &f)
Return a Field for the given ID.
Definition Representation.hpp:225
MemSizeConfig< sizeof(void *)>::memsize_t memsize_t
MemCore::WeakPtr< VRenderContext::RenderParameter > operator<<=(const Anemone_Context_String_t &ACS, const Value &V)
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
gridop_API RefPtr< Grid > DEPRECATED("Use grid/types/RegularGrid3D.hpp:UniformGrid3D instead", createUniformGrid(const string &InputGridname, const Info< Skeleton > &Level, const string &OutputGridname, const MultiIndex< 3 > &Resolution, const RefPtr< Eagle::BoundingBox > &SubBox=NullPtr()))
Create a uniform Grid from a given Grid.
std::nullptr_t NullPtr
A proxy object that looks like a RefPtr<Field> but equips fields with a FieldCreator and a FragmentID...
Definition Representation.hpp:37