FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
Bundle.hpp
1#ifndef __FIBER_BUNDLE_HPP
2#define __FIBER_BUNDLE_HPP "Created 27.02.2001 21:42:27 by werner"
3
4#include "BundleAPI.h"
5#include <fiber/grid/Grid.hpp>
6#include <memcore/Persistencer.hpp>
7#include <memcore/Loader.hpp>
8#include <list>
9#include "GridID.hpp"
10#include "Slice.hpp"
11#include "ParameterSpace.hpp"
12#include "SkeletonInfo.hpp"
13#include "Binder.hpp"
14
15namespace MemCore
16{
17
18template <>
19struct BUNDLE_API DeferredInitializationTrait<Fiber::OwnerOf<Fiber::Slice>::reference_domain_t>
20{
22};
23
24}
25
26namespace Fiber
27{
28 using std::list;
29 using std::string;
31
42#ifndef __FIBER_BUNDLE_STORAGETRANSFORMATIONS_HPP
43class BUNDLE_API StorageTransformations;
44#endif
45
46using RefPtrStorageTransformations = RefPtr<StorageTransformations,
48
58template <class ObjectLevel>
59 class BUNDLE_API EvolutionIterator;
60
74
75
80template <>
81class BUNDLE_API EvolutionIterator<Slice>
82{
83public:
84 virtual ~EvolutionIterator();
85
86 virtual bool apply(ParameterSet&P, Slice&S) = 0;
87};
88
94template <>
95class BUNDLE_API EvolutionIterator<Grid>
96{
97public:
98 virtual ~EvolutionIterator();
99
100 virtual bool apply(double t, GridID&id, Grid&g) = 0;
101
103 using functor = std::function<bool(double t, GridID&id, Grid&g)>;
104};
105
111template <>
112class BUNDLE_API EvolutionIterator<Skeleton>
113{
114public:
115 virtual ~EvolutionIterator();
116
117 virtual bool apply(double t, const RefPtr<Skeleton>&S) = 0;
118};
119
120template <>
121class BUNDLE_API EvolutionIterator<Field>
122{
123public:
124 ~EvolutionIterator();
125};
126
132{
133public:
135
139 virtual bool OpenFile(const string&fname);
140
144 virtual bool CreateSlice(double t);
145
149 virtual bool CreateGrid(const RefPtr<GridID>&gname, Grid&G, double t);
150
154 virtual bool CreateField(const RefPtr<GridID>&gname, Grid&G, double t, const string&fieldname);
155};
156
169class BUNDLE_API Bundle : public OwnerOf<Slice>
170 , public Intercube
171 , public Attributes
172 , public MemCore::Ageable
173{
174 ParameterList AvailableParameters;
176
177 friend class Slice;
178
179 typedef RefPtr<Slice> P0D_t;
182
183 P0D_t P0D;
184 P1D_t P1D;
185 P2D_t P2D;
186
187// map<ParameterSet, ParameterSpace> ParameterSpaces;
188
189 RefPtr<GridList> myGridList;
190
191 bool processOwnership(MemCore::Intercube&Output,
192 const MemCore::Intercube&Input) const override;
193
194 void x_updateOwnershipAge(const MemCore::Ageable&) override;
195
196 RefPtr<Binder> myBinder;
197
198public:
199
201
202 const RefPtr<GridList>&getGridList() const
203 {
204 return myGridList;
205 }
206
207 const set<WeakPtr<GridID> >&getGridIdentifiers() const;
208
214 struct BUNDLE_API Notifier : public ReferenceBase<Notifier>
215 {
216 Notifier();
217
218 protected:
219 virtual ~Notifier();
220
221 public:
222 virtual void notifyChange(const Bundle&B) = 0;
223 };
224
225 std::set<RefPtr<Notifier>> myNotifiers;
226
231 void announceModification() const;
232
233 void addNotifier(const RefPtr<Notifier>&N);
234
235
236 void bind(const RefPtr<Binder>&theBinder)
237 {
238 myBinder = theBinder;
239 }
240
241
249 bindTo(const string&url,
250 const RefPtr<MemCore::InterfaceBase>&A = nullptr,
251 const RefPtr<MemCore::InterfaceBase>&B = nullptr);
252
258 bindToNew(const string&url, const RefPtrStorageTransformations&ST);
259
261 bindToNew(const string&url);
262
263 const RefPtr<Binder>&getBinder() const
264 {
265 return myBinder;
266 }
267
271 bool isBound() const
272 {
273 return getBinder().valid();
274 }
275
281 {
282 if (myBinder)
283 return myBinder->getUrl();
284
285 return std::string();
286 }
287
288
298 bool sync(const RefPtr<MemCore::LoaderProgress>&SaveProgress = nullptr ) const;
299
315static RefPtr<Bundle> load(bool&success, const RefPtr<LoaderParameters>&ld, const RefPtr<Bundle>&B = nullptr );
316
322static RefPtr<Bundle> load(bool&success, const list<string>&urls,
323 const RefPtr<Bundle>&B = nullptr,
324 const RefPtr<LoaderProgress>&Progress = nullptr)
325 {
327 if (Progress)
328 LP->setProgressCallbacks( Progress );
329
330 return load(success, LP, B);
331 LP->load_failure;
332 }
333
343 load( const list<string>&urls,
344 const RefPtr<LoaderProgress>&Progress = nullptr)
345 {
347 if (Progress)
348 LP->setProgressCallbacks( Progress );
349
350 bool success = false;
351 RefPtr<Bundle> B = load(success, LP);
352 if (success)
353 return {B, {} };
354 else
355 return {nullptr, LP->load_failure};
356 }
357
358
359static RefPtr<Bundle> load(bool&success, const string&url,
360 const RefPtr<Bundle>&B = nullptr,
361 const RefPtr<LoaderProgress>&Progress = nullptr)
362 {
363 return load(success, list<string>{url}, B, Progress);
364 }
365
366static RefPtr<Bundle> load(const string&url, const RefPtr<LoaderProgress>&Progress = nullptr )
367 {
368 bool Success = false;
369 RefPtr<Bundle> BP = load(Success, url, nullptr, Progress);
370 if (Success)
371 return BP;
372 return nullptr;
373 }
374
375
384 bool merge(const RefPtr<LoaderParameters>&LP);
385
386 bool merge(const string&url);
387
388 bool merge(const list<string>&urls);
389
390
392 Bundle();
393
402 void DeferredConstructor();
403
405 ~Bundle();
406
407 int save(const string&url,
408 const RefPtr<LoaderProgress>&SaveProgress = nullptr,
409 const RefPtrStorageTransformations&ST = nullptr);
410
414 RefPtr<GridID> operator()(const string&gridname) const
415 {
416 if (myGridList)
417 return (*myGridList)(gridname);
418
419 return nullptr;
420 }
421
425 RefPtr<GridID> operator[](const string&gridname) const
426 {
427 if (myGridList)
428 return (*myGridList)[gridname];
429
430 return nullptr;
431 }
432
437 {
438 if (myGridList)
439 return myGridList->getGridnames(Gridnames);
440
441 return 0;
442 }
443
447 size_t getNumberOfGrids() const
448 {
449 if (myGridList)
450 return myGridList->getNumberOfGrids();
451
452 return 0;
453 }
454
456 const RefPtr<GlobalCharts>&getAtlas() const
457 {
458 return Atlas;
459 }
460
464 double minTime() const;
465
469 double maxTime() const;
470
473
476
479
481 SliceInfo_t firstSlice() const;
482
488 bool accessFirstSlice() const
489 {
490 SliceInfo_t SI = firstSlice();
491 if (SI.second)
492 return SI.second->accessSlice();
493
494 return false;
495 }
496
498 Slice&operator[](double time);
499
502
504 SlicePtr operator()(double&time) const;
505
506 SlicePtr findPrev(double&time) const;
507 SlicePtr findNext(double&time) const;
508
510 SliceInfo_t prev(double time) const
511 {
513 retval.first = time;
514 retval.second = findPrev(retval.first);
515 return retval;
516 }
517
519 SliceInfo_t next(double time) const
520 {
522 retval.first = time;
523 retval.second = findNext(retval.first);
524 return retval;
525 }
526
530 RefPtr<Grid> operator()(double time, const string&gridname) const
531 {
532 RefPtr<Slice> S = (*this)(time);
533 if (S)
534 return (*S)(gridname);
535 return nullptr;
536 }
537
542 {
543 RefPtr<Slice> S = (*this)(time);
544 if (S)
545 return (*S)(GridID);
546 return nullptr;
547 }
548
549 Slice::grids_t::value_type getUniqueGrid(double time);
557 {
558 return new Grid( getGridList(), Atlas);
559 }
560
567 Info<Grid> findFirst(const string&gridname, bool OnlyInspectLoadedSlices = false) const;
568
576 Info<Grid> findLast(const string&gridname, bool OnlyInspectLoadedSlices = false) const;
577
583 int NumberOfGrids(const string&gridname, bool OnlyInspectLoadedSlices) const;
584
590 int NumberOfGrids( double T0, double T1, const string&gridname, bool OnlyInspectLoadedSlices ) const;
591
592
593 int NumberOfGridInstances( double T0, double T1, const string&gridname, bool OnlyInspectLoadedSlices ) const
594 {
595 return NumberOfGrids( T0, T1, gridname, OnlyInspectLoadedSlices );
596 }
597
598 int getNrSlicesOfGridInTimeRange( double time_min, double time_max, const string& grid_name, bool loaded_slices_only ) const;
599
604 GridInfo_t findMostRecentGrid(double time, const string&gridname) const;
605
610 GridInfo_t findMostRecentGrid(double time, const RefPtr<GridID>&gridid) const;
611
617 Info<Grid> findPrev(double time, const string&gridname) const;
618 Info<Grid> findPrev(double time, const RefPtr<GridID>&gridname) const;
619
620
621 GridInfo_t findPreviousGrid(double time, const string&gridname) const;
622 GridInfo_t findPreviousGrid(double time, const RefPtr<GridID>&GID) const;
623
629 Info<Grid> findNext(double time, const string&gridname) const;
630 Info<Grid> findNext(double time, const RefPtr<GridID>&gridname) const;
631
640 int iterateBackward(double&time, const string&gridname, EvolutionIterator<Grid>&GEI, bool IterateOnlyLoadedSlices) const;
641
650 int iterateForward (double&time, const string&gridname,
651 EvolutionIterator<Grid>&GEI,
652 bool IterateOnlyLoadedSlices) const;
653
654 SkeletonInfo_t findPreviousRefinementLevel(double&T, const string&gridname, int Level,
655 EvolutionIterator<Skeleton>*EIS, int IndexDepth);
656
661 SkeletonInfo_t findPreviousRefinementLevel(double&T, const string&gridname, int Level, int IndexDepth = 0)
662 {
663 return findPreviousRefinementLevel(T,gridname,Level,0,IndexDepth);
664 }
665
666 SkeletonInfo_t findPreviousRefinementLevel(double&T, const string&gridname, int Level,
667 EvolutionIterator<Skeleton>&EIS, int IndexDepth=0)
668 {
669 return findPreviousRefinementLevel(T,gridname,Level,&EIS,IndexDepth);
670 }
671
672private:
673 SkeletonInfo_t findNextRefinementLevel(P1D_t::const_iterator&it, const string&gridname, int Level, int IndexDepth);
674
675public:
676 SkeletonInfo_t findNextRefinementLevel(double&T, const string&gridname, int Level, int IndexDepth = 0);
677
678
681
686 int sizeP1D() const
687 {
688 return int( P1D.size() );
689 }
690
691
692 const ParameterList&AllParameters() const
693 {
694 return AvailableParameters;
695 }
696
700 int iterate(const ParameterList&PL, EvolutionIterator<Slice>&SI) const;
701
702
707 int iterate(const string&gridname, EvolutionIterator<Grid>&GEI, bool IterateOnlyLoadedSlices) const;
708
710 int iterate(const string&gridname, const EvolutionIterator<Grid>::functor&GEI, bool IterateOnlyLoadedSlices) const;
711
712 using grid_iterator = std::function<bool(double t, const GridID&id, Grid&g)>;
713
718 int iterate(const RefPtr<GridID>&id, const grid_iterator&gi, bool IterateOnlyLoadedSlices=false) const;
719
720
732 template <class Functor>
734 {
735 int N = 0;
736 for(const auto&P1 : P1D)
737 {
738 if (!P1.second) continue;
739 if (DoLoadAllSlices)
740 P1.second->accessSlice();
741
742 if (F(P1.first, *P1.second))
743 N++;
744 else
745 return N;
746 }
747 return N;
748 }
749
750 typedef std::pair<double,double> Range_t;
751
755 Range_t getTimeRange(const string&Gridname, bool OnlyInspectAlreadyLoadedSlices=false);
756
763 int getMemoryUsage(memsize_t&UsedMemory, memsize_t&WantedMemory) const;
764
765 string xml() const;
766
767 void extremeUnction() override;
768};
769
770
771
778class BUNDLE_API BundlePtr : public RefPtr<Bundle>
779{
780public:
781 using RefPtr<Bundle>::operator void*;
782 using RefPtr<Bundle>::operator !;
783
785 BundlePtr();
786
788 BundlePtr(const BundlePtr&) = default;
789
792
794
796 ~BundlePtr();
797
799 BundlePtr&operator=(const BundlePtr&) = default;
800
804 Bundle&create();
805
812 {
813 return create();
814 }
815
816 Bundle& operator*() const
817 {
819 }
820
827 Slice&operator[](double time)
828 {
829 Bundle&B = (**this);
830 return B[time];
831 }
832
837 SlicePtr operator()(double&time)
838 {
839 if (!*this) return nullptr;
840 return (**this)(time);
841 }
842
854 int save(const string&url,
855 const RefPtr<LoaderProgress>&SaveProgress = nullptr,
856 const RefPtrStorageTransformations&ST = nullptr);
857
861 int saveGrids(const string&url, const RefPtr<MemCore::StringList>&SaveableGridNames,
862 const RefPtr<LoaderProgress>&SaveProgress = nullptr,
863 const RefPtrStorageTransformations&ST = nullptr );
864
865 bool load(const string&url, const RefPtr<LoaderProgress>&Progress = nullptr );
866 bool load(const list<string>&urls, const RefPtr<LoaderProgress>&Progress = nullptr );
867};
868
869
870template <>
871class Iterator<Slice> : public EvolutionIterator<Slice>
872{
873};
874
875
876} /* namespace Fiber */
877
878#endif /* __FIBER_BUNDLE_HPP */
strong_ordering operator(const error_code &__lhs, const error_code &__rhs) noexcept
_Expr< _ValFunClos< _ValArray, _Tp >, _Tp > apply(_Tp __func(_Tp)) const
constexpr _OutputIterator merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
basic_string< char > string
constexpr _Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type bind(_Func &&__f, _BoundArgs &&... __args)
size_type size() const noexcept
Loading progress callback functor.
Definition Bundle.hpp:132
Convenience class that implements a pointer to a Bundle object but adds some useful member funtions t...
Definition Bundle.hpp:779
Bundle & operator*()
Dereferencing operator - it will always yield a valid object, if the bundle pointer was not yet initi...
Definition Bundle.hpp:811
Slice & operator[](double time)
Convenient slice access function.
Definition Bundle.hpp:827
BundlePtr(const BundlePtr &)=default
Copy Constructor.
BundlePtr & operator=(const BundlePtr &)=default
Assignment.
SlicePtr operator()(double &time)
Request a Slice without creating any data.
Definition Bundle.hpp:837
The main entity holding all information.
Definition Bundle.hpp:173
Info< Skeleton > SkeletonInfo_t
The information as returned by a query for Skeletons.
Definition Bundle.hpp:478
SliceInfo_t prev(double time) const
Return the time slice just before the given time.
Definition Bundle.hpp:510
static std::pair< RefPtr< Bundle >, std::string > load(const list< string > &urls, const RefPtr< LoaderProgress > &Progress=nullptr)
Convenience function to load a bundle from a given list of urls, returning a pair of a bundle pointer...
Definition Bundle.hpp:343
int getGridnames(GridList::stringset_t &Gridnames) const
Query all the grid names that lurk around at this Bundle.
Definition Bundle.hpp:436
std::string boundUrl() const
The URL of the storage device to which this Bundle is bound.
Definition Bundle.hpp:280
RefPtr< GridID > operator[](const string &gridname) const
Create a GridID from a name.
Definition Bundle.hpp:425
int iterate_timeslices(bool DoLoadAllSlices, const Functor &F) const
Definition Bundle.hpp:733
static RefPtr< Bundle > load(bool &success, const list< string > &urls, const RefPtr< Bundle > &B=nullptr, const RefPtr< LoaderProgress > &Progress=nullptr)
A simplified version to load a Bundle without detailed error information availlable (which would be i...
Definition Bundle.hpp:322
Info< Grid > GridInfo_t
The information as returned by a query for Grids.
Definition Bundle.hpp:475
size_t getNumberOfGrids() const
Get the number of grids defined on this Grid.
Definition Bundle.hpp:447
SkeletonInfo_t findPreviousRefinementLevel(double &T, const string &gridname, int Level, int IndexDepth=0)
Find the most recent refinement level of an adaptive mesh, which resides at a time before the current...
Definition Bundle.hpp:661
bool accessFirstSlice() const
Access the first slice of this bundle, which implies loading or creating any metadata as associated w...
Definition Bundle.hpp:488
bool isBound() const
Check if this bundle is bound.
Definition Bundle.hpp:271
SliceInfo_t next(double time) const
Return the time slice just next after the given time.
Definition Bundle.hpp:519
RefPtr< Grid > operator()(double time, const string &gridname) const
Query the one-dimensional index space for a Grid.
Definition Bundle.hpp:530
RefPtr< Slice > operator()(const ParameterSet &) const
Query the n-dimensional index space for a Slice entry.
int sizeP1D() const
The size of the one-dimensional parameter space.
Definition Bundle.hpp:686
RefPtr< Grid > newGrid() const
Create a new Grid object that lives on this Bundle, but is not yet associated to any time,...
Definition Bundle.hpp:556
MemCore::SaveParameters::SaveError bindToNew(const string &url, const RefPtrStorageTransformations &ST)
Bind to a newly created file.
Info< Slice > SliceInfo_t
The information as returned by a query for Slices.
Definition Bundle.hpp:472
RefPtr< Grid > operator()(double time, const RefPtr< GridID > &GridID) const
Query the one-dimensional index space for a Grid.
Definition Bundle.hpp:541
Slice & operator[](const ParameterSet &)
Access n-dimensional index space, possibly creating an Slice entry.
RefPtr< GridID > operator()(const string &gridname) const
Query a GridID from a name.
Definition Bundle.hpp:414
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
A grid identifier.
Definition GridID.hpp:29
A Grid is a set of Skeleton objects, each of them accessed via some unique SkeletonID object.
Definition Grid.hpp:60
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
Definition ParameterSpace.hpp:83
Definition ParameterSpace.hpp:49
A Skeleton is a set of Representation object, each of them accessed by an Representer object.
Definition Skeleton.hpp:102
Convenience shortcut for pointers to Slices.
Definition Slice.hpp:232
Information per time slice, mainly a set of Grid objects that are accessed via GridID objects.
Definition Slice.hpp:36
refvalue_t & operator*() const
MemSizeConfig< sizeof(void *)>::memsize_t memsize_t
RefPtr< ValueNotifier > addNotifier(TypedSlot< SlotType > &theSlot, VObjectClass *That)
Column< C, Value > operator*(const Column< C, Value > &A, double V)
double P1(double x)
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
typename Ownable< OwnedObjectType, ContainerBase >::Container OwnerOf
Shortcut to find the owning type.
Definition Ownable.hpp:265
StrongPtr< Object, ObjectBase > RefPtr
Mechanism to have notifier objects listening to changes on the Bundle, whatever nature those changes ...
Definition Bundle.hpp:215
Definition Bundle.hpp:65
The information as returned by a query for Skeletons.
Definition SkeletonInfo.hpp:20
The information as returned by a query for Slices.
Definition SliceInfo.hpp:37