FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
DirectProductArray.hpp
1#ifndef __FIBER_DIRECTPRODUCT_HPP
2#define __FIBER_DIRECTPRODUCT_HPP
3
4#ifndef DONT_USE_PRAGMA_ONCE
5#pragma once
6#endif
7
8#include "MemArray.hpp"
9#include "CoordinateAxisArray.hpp"
10
11namespace Fiber
12{
13using std::type_info;
14
15
47template <class T, class Category, int MDIMS>
49{
50protected:
51
53 {}
54
55public:
56
57#ifdef HAVE_OLD_MEMARRAY
58 /*
59 * Silences the compiler of overloaded virtual hiding, which is not the case here
60 */
61 using MemArrayBase<MDIMS>::newMemArray;
62// using MemArrayBase<MDIMS>::createMemArray;
63#endif
64
66 typedef typename T::value_type component_type;
67
69
70 enum
71 {
73 COMPONENTS = T::SIZE,
75 Dims = MDIMS
76 };
77
80
87
92
99 : MemBase(FiberType<T>::getFiberType()->getFiberTypeIndex(), C)
100 , MemArrayBase<MDIMS>(FiberType<T>::getFiberType()->getFiberTypeIndex(), C )
101 {
102 for(int i=0; i<Dims; i++)
103 {
104 if (i<COMPONENTS)
105 ComponentMap[ i ] = i;
106 else
107 ComponentMap[ i ] = -1;
108 }
109 }
110
113 const MemBase::Creator_t&theCreator = MemCore::NullPtr() )
114 : MemArrayBase<MDIMS>(FiberType<T>::getFiberType()->getFiberTypeIndex(), theCreator)
115 {
116 for(int i=0; i<COMPONENTS; i++)
117 {
118 Components[i] = C[i];
119 }
120
121 for(int i=0; i<Dims; i++)
122 {
123 ComponentMap[ i ] = CMap[i];
124 }
125 }
126
127 DirectProductMemArrayBase(const DirectProductMemArrayBase&Src, const MemBase::Creator_t&theCreator = MemCore::NullPtr() )
128 : MemArrayBase<MDIMS>(FiberType<T>::getFiberType()->getFiberTypeIndex(), theCreator)
129 {
130 for(int i=0; i<COMPONENTS; i++)
131 {
132 if (Src.Components[i] )
133 Components[i] = new CoordinateAxisArray_t( *Src.Components[i] );
134 }
135 ComponentMap = Src.ComponentMap;
136 }
137
142
143 MemCore::memsize_t memsize() const override
144 {
145 return 0;
146 }
147
148#ifdef HAVE_OLD_MEMARRAY
149 //TODO: was marked as override, but doesn't
150 RefPtr<MemBase> newMemArray() const
151 {
152 return new MemArray<MDIMS, T>( this->Size() );
153 }
154#endif
155
156 bool copyFrom(const RefPtr<MemCore::ChunkBase>&theChunk) override
157 {
158 return false;
159 }
160
167 {
168 if (!Data) return MemCore::NullPtr();
169 if (Data->elements() != Size().size() )
170 return MemCore::NullPtr();
171
172 return new MemArray<MDIMS,T>(Data, Size(), C );
173 }
174
185
186 RefPtr<MemBase> getComponentArray(int member, const MemBase::Creator_t&C) override
187 {
188 return MemCore::NullPtr();
189 }
190
194 void retrieve(T&retval, const MultiIndex<Dims>&I) const
195 {
196 for(int i=0; i<Dims; i++)
197 {
198 int component = ComponentMap[ i ];
200 continue;
201
202 const RefPtr<CoordinateAxisArray_t>&that = Components[ component ];
203
204 if (that)
205 retval[ component ] = (*that)( I[i] );
206 }
207 }
208
222 {
223 FloatIndex_t result;
224 for(int i=0; i<Dims; i++)
225 {
226 int component = ComponentMap[ i ];
228 continue;
229
230 if (const RefPtr<CoordinateAxisArray_t>&that = Components[ component ] )
231 {
232 result[ component ] = that->reverse( PointCoordinates[i] );
233 }
234 }
235 return result;
236 }
237
238#if 0 // that->locate( .. ) is disabled
243 bool locate(T&pos) const
244 {
245 for(int i=0; i<Dims; i++)
246 {
247 int component = ComponentMap[ i ];
249 {
250 continue;
251 }
252
253 const RefPtr<CoordinateAxisArray_t>&that = Components[ component ];
254
255 if (!that)
256 return false;
257
258 if (!that->locate( pos[ component ] ) )
259 return false;
260 }
261
262 return true;
263 }
264#endif
269 MultiIndex<Dims> Size() const override
270 {
272 for(int i=0; i<Dims; i++)
273 {
274 int component = ComponentMap[ i ];
276 {
277 Sz[ i ] = 1;
278 continue;
279 }
280 const RefPtr<CoordinateAxisArray_t>&that = Components[ component ];
281 Sz[i] = that->Length();
282 }
283 return Sz;
284 }
285
289 {
291 for(int i=0; i<Dims; i++)
292 I[i] = 0;
293
294 return I;
295 }
296
301 {
303 const MultiIndex<Dims>&Sz = this->Size();
304 for(int i=0; i<Dims; i++)
305 {
306 index_t sz = Sz[i];
307 if (sz>1)
308 I[i] = sz - 1;
309 else
310 I[i] = 0;
311 }
312 return I;
313// return Size() - MIndex(1,1,1);
314 }
315
316// CreativeIterator<T>* creativeIterator() override
317// {
318// return 0;
319// }
320
321/*
323 const type_info&getType() const override
324 {
325 return typeid(T);
326 }
327
329 const FiberTypeBase&getFiberType() const override
330 {
331 return FiberType<T>::getFiberType();
332 }
333*/
334
335
337 {
338 return MemCore::NullPtr(); // not yet implemented...
339 }
340
342 void*getPtr() override
343 {
344 return 0;
345 }
346
347 HyperslabParameters& getHyperslabParameters() override
348 {
349 static HyperslabParameters nix(0,0,0);
350 return nix;
351 }
352/*
353 RefPtr<UntypedCreativeIterator> getIterator() const
354 {
355 return MemCore::NullPtr() override;
356 }
357*/
358};
359
361
365template <class T, class Category = LinearCoordinateAxisArray, int MDIMS = T::SIZE>
366class DirectProductMemArray : public DirectProductMemArrayBase<typename T::FixedArray_t, Category, MDIMS>, public TypedArray<T>
367{
368protected:
370 {}
371
372public:
374
376 typedef T value_type;
377
379 typedef typename T::value_type component_type;
380
383
384 enum
385 {
388 };
389
395// T origin;
396
401 template <class TBase>
407
409 : MemBase(FiberType<T>::getFiberType()->getFiberTypeIndex(), C) // don't use creators here, these arrays don't take significant memory
410 , TypedArray<T>( C )
411 {}
412
413 DirectProductMemArray(const DirectProductMemArray&DPM, const MemBase::Creator_t&C = MemCore::NullPtr() )
414 : MemBase(FiberType<T>::getFiberType()->getFiberTypeIndex(), C)
415 , DirectProductMemArrayBase_t(DPM, C)
416 , TypedArray<T>( C )
417 {}
418
419 T operator[](const MultiIndex<Dims>&I) const
420 {
421 T retval;// = origin;
422 this->retrieve( retval, I );
423 return retval;
424 }
425
426 T getElement(const index_t i) const
427 {
428 const MultiIndex<Dims> I(i, this->Size(), CreateFromLinear{} );
429 return (*this)[I];
430 }
431
432 std::string getElementAsString(size_t index) const override
433 {
434 const MultiIndex<Dims> I(index, this->Size(), CreateFromLinear{} );
435 if (I.isWithin( this->Size() ))
436 return std::to_string( (*this)[I] );
437
438 return {};
439 }
440
441 RefPtr<MemBase> copy(const MemBase::Creator_t&C = nullptr) const override
442 {
443 return new DirectProductMemArray(*this, C);
444 }
445
446
451 {
452 MultiIndex<Dims> Sz = this->Size();
453
454 RefPtr<MemArray_t> M = new MemArray_t( Sz, C );
455 typename MemArray_t::MultiArray_t&dst = *M;
456
458
459 T val;// = origin;
460 do
461 {
462 this-> retrieve( val, idx);
463 dst[idx] = val;
464
465/*
466 cannot use retrieve(dst[idx]) here, because dst[idx] might be an ElementProxy type,
467 and passing such as non-const reference doesnt work.
468 would be interesting how to fix that. if it is possible at all.
469 */
470// retrieve( dst[idx], idx);
471 }
472 while( idx.inc( Sz ) );
473
474 return M;
475 }
476
477 RefPtr<MemBase> newMemArraynD(const MultiIndex<Dims>&, const MemBase::Creator_t&C) const override
478 {
479 return MemCore::NullPtr();
480 }
481
482 RefPtr<MemBase> createSubMemArray(const MultiIndex<Dims>&, const MultiIndex<Dims>&, const MemBase::Creator_t&C) const override
483 {
484 return MemCore::NullPtr();
485 }
486
487#if 0
489 MemCore::WeakPtr<FiberTypeBase> getFiberType() const override
490 {
492 }
493#endif
494
496 const type_info&getType() const override
497 {
498 return typeid(T);
499 }
500
503 {
504 return nullptr;
505 }
506
508 const CreativeIterator<T>* creativeIterator() const override
509 {
510 return nullptr;
511 }
512
515 {
516 return nullptr;
517 }
518
519 const void*OriginPtr() const override { return nullptr; }
520 const void*DeltaPtr() const override { return nullptr; }
521
522
524 T first() const override
525 {
526 return (*this)[ this->firstIndex() ];
527 }
528
530 T last() const override
531 {
532 return (*this)[ this->lastIndex() ];
533 }
534
535};
536
537
550template <class T, class DeltaT = T, int MDIMS = T::SIZE>
551class LinearDirectProductMemArray : public DirectProductMemArray<T, LinearCoordinateAxisArray, MDIMS>
552{
553protected:
555 {}
556
557public:
559
561
562 using Base_t::Components;
563
564 enum { COMPONENTS = T::SIZE };
565
567 typedef typename T::value_type component_type;
568
569 const T baseValue;
570 const DeltaT deltaValue;
571
572// virtual const T&Origin() const = 0;
573// virtual const T&Delta() const = 0;
574
575
576 const void*OriginPtr() const override { return &Origin(); }
577 const void*DeltaPtr() const override { return &Delta(); }
578
579 const T&Origin() const { return baseValue; }
580 const DeltaT&Delta() const { return deltaValue; }
581
590 LinearDirectProductMemArray(const index_t dims[MDIMS], const T&base, const DeltaT&delta, const MemBase::Creator_t&C = MemCore::NullPtr() )
591 : MemBase(FiberType<T>::getFiberType()->getFiberTypeIndex(), C)
593 , baseValue(base)
594 , deltaValue(delta)
595 {
596// puts("LinearDirectProductMemArray(const index_t dims[MDIMS], const T&base, const DeltaT&delta, const MemBase::Creator_t&C = MemCore::NullPtr() )");fflush(stdout);
597
598 for(int c=0; c<COMPONENTS; c++)
599 {
600 if (c<MDIMS)
601 this->Components[c] = new CoordinateAxisArray_t( base[c], delta[c], dims[c] );
602 }
603 }
604
610 : MemBase(FiberType<T>::getFiberType()->getFiberTypeIndex(), C)
612 , baseValue(base)
613 , deltaValue(delta)
614 {
615// puts("LinearDirectProductMemArray(const MultiIndex<MDIMS>&dims, const T&base, const DeltaT&delta, const MemBase::Creator_t&C = MemCore::NullPtr() )");fflush(stdout);
616
617 for(int c=0; c<COMPONENTS; c++)
618 {
619 if (c<MDIMS)
620 {
621 this->Components[c] = new CoordinateAxisArray_t( base[c], delta[c], dims[c] );
622 }
623 }
624 }
625
627 : MemBase(FiberType<T>::getFiberType()->getFiberTypeIndex(), C)
629 {}
630
631#if 0
632 bool resize(int component, index_t newSize)
633 {
634 if (RefPtr<LinearArray<component_type> > LA = Components[component])
635 {
636 LA->resize( newSize );
637 return true;
638 }
639 return false;
640 }
641#endif
642
647 bool getFlooredMultiIndex( const T& pos, MultiIndex<MDIMS>& index ) const
648 {
649// if( info )
650// {
651// Verbose( 0 ) << "LinearDirectProductMemArray::getFlooredMultiIndex() ";
652// Verbose( 0 ) << "'crds: " << pos << ", origin: " << baseValue << ", delta: " << deltaValue;
653// }
654
655 for( unsigned i = 0; i < MDIMS; ++i )
656 {
657 if ( (pos[i] - baseValue[i]) / deltaValue[i] >= 0)
658 {
659 index[i] = size_t( floor( ( pos[i] - baseValue[i] ) / deltaValue[i] ) );
660 }
661 else
662 {
663 Verbose( 51 ) << "LinearDirectProductMemArray::getFlooredMultiIndex() Fragment Index " << i << " negative";
664 Verbose( 51 ) << "'crds: " << pos << ", origin: " << baseValue << ", delta: " << deltaValue;
665 return false;
666 }
667
668
669 int component = this->ComponentMap[ i ];
670 if( index[i] >= this->Components[ component ]->Length() )
671 {
672 Verbose( 51 ) << "LinearDirectProductMemArray::getFlooredMultiIndex() Fragment Index " << i << " too large: " << index[i] << ">=" << this->ComponentMap[i];
673 Verbose( 51 ) << "'crds: " << pos << ", origin: " << baseValue << ", delta: " << deltaValue;
674 return false;
675 }
676 }
677
678 return true;
679 }
680
685 bool getNearestMultiIndex( const T& pos, MultiIndex<MDIMS>& index ) const
686 {
687 for( unsigned i = 0; i < MDIMS; ++i )
688 {
689 if ( (pos[i] - baseValue[i]) / deltaValue[i] >= 0)
690 {
691 index[i] = size_t( round( ( pos[i] - baseValue[i] ) / deltaValue[i] ) );
692 }
693 else
694 {
695 Verbose(51) << "LinearDirectProductMemArray::getNearestMultiIndex() Fragment Index " << i << " negative";
696 Verbose(51) << "'crds: " << pos << ", origin: " << baseValue << ", delta: " << deltaValue;
697 return false;
698 }
699
700 int component = this->ComponentMap[ i ];
701 if( index[i] >= this->Components[ component ]->Length() )
702 {
703 Verbose(51) << "LinearDirectProductMemArray::getNearestMultiIndex() Fragment Index " << i << " too large: " << index[i] << ">=" << this->ComponentMap[i];
704 Verbose(51) << "'crds: " << pos << ", origin: " << baseValue << ", delta: " << deltaValue;
705 return false;
706 }
707 }
708
709 return true;
710 }
711};
712
713} /* namespace Fiber */
714
715#endif /* __FIBER_DIRECTPRODUCT_HPP */
constexpr __enable_if_is_duration< _ToDur > floor(const duration< _Rep, _Period > &__d)
constexpr enable_if_t< __and_< __is_duration< _ToDur >, __not_< treat_as_floating_point< typename _ToDur::rep > > >::value, _ToDur > round(const duration< _Rep, _Period > &__d)
void resize(size_t __size, _Tp __c=_Tp())
valarray< size_t > size() 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
Class for creating structured types as direct product of one-dimensional arrays.
Definition DirectProductArray.hpp:49
RefPtr< CoordinateAxisArray_t > Components[COMPONENTS]
The respective components of the array.
Definition DirectProductArray.hpp:79
@ Dims
The dimensionality of the base manifold.
Definition DirectProductArray.hpp:75
@ COMPONENTS
The number of components of the value type.
Definition DirectProductArray.hpp:73
Eagle::Vector< int, Dims > ComponentMap
Mapping from manifold dimension to component array.
Definition DirectProductArray.hpp:86
MultiIndex< Dims > firstIndex() const
Return a multidimensional index for the 1st data element, which is just all components to be zero.
Definition DirectProductArray.hpp:288
FloatIndex_t getIndex(const T &PointCoordinates) const
Given the coordinates of a point, yield the index where it resides in the array.
Definition DirectProductArray.hpp:221
T::value_type component_type
The components of the structured type T.
Definition DirectProductArray.hpp:66
void * getPtr() override
Implementation of the virtual MemArray function.
Definition DirectProductArray.hpp:342
RefPtr< MemArray< MDIMS, T > > createMemArray(const RefPtr< MemCore::ChunkBase > &Data, const MemBase::Creator_t &C) const
Create a memory array of the same dimensions as the current array, but with data as provided by the S...
Definition DirectProductArray.hpp:166
RefPtr< MemBase > createEquallySizedMemArray(const RefPtr< MemCore::ChunkBase > &Storage, const MemBase::Creator_t &C) const override
Create a memory array of the same dimensions as the current array, but with data as provided by the S...
Definition DirectProductArray.hpp:181
MultiIndex< Dims > Size() const override
Return the multidimensional number of points covered by this array.
Definition DirectProductArray.hpp:269
void retrieve(T &retval, const MultiIndex< Dims > &I) const
Evaluate an index, deliver the coordinate value.
Definition DirectProductArray.hpp:194
void DeferredConstructor() override
Virtual deferred reference pointer construction pointer Don't overload if you don't know exactly what...
Definition DirectProductArray.hpp:138
DirectProductMemArrayBase(const MemBase::Creator_t &C=MemCore::NullPtr())
The constructor sets the component map such that the dimensions of the manifold are mapped to the fir...
Definition DirectProductArray.hpp:98
FixedArray< double, MDIMS > FloatIndex_t
A multidimensional floating-point index.
Definition DirectProductArray.hpp:91
RefPtr< MemBase > getSlice(index_t i, const MemBase::Creator_t &C) const override
For a multidimensional array retrieve the nth slice.
Definition DirectProductArray.hpp:336
MultiIndex< Dims > lastIndex() const
Return a multidimensional index for the last data element, which is just the largest index in each di...
Definition DirectProductArray.hpp:300
Definition DirectProductArray.hpp:367
T value_type
The type of values that are delivered here.
Definition DirectProductArray.hpp:376
T::value_type component_type
The type of the elements of each component.
Definition DirectProductArray.hpp:379
const void * OriginPtr() const override
Get pointer to origin of linearly procedural array, if it is linear.
Definition DirectProductArray.hpp:519
DirectProductMemArray(const DirectProductMemArrayCreateBaseArray &, const DirectProductMemArray< TBase, Category > &D, const MemBase::Creator_t &C=MemCore::NullPtr())
The base value which is used as default for each component when the ComponentMap does not specify a m...
Definition DirectProductArray.hpp:402
CreativeIterator< T > * creativeIterator() override
Procedural arrays return 0 here.
Definition DirectProductArray.hpp:502
const void * DeltaPtr() const override
Get pointer to delta of linearly procedural array, if it is linear.
Definition DirectProductArray.hpp:520
MultiIndex< Dims > Size() const override
Return the multidimensional number of points covered by this array.
Definition DirectProductArray.hpp:269
T last() const override
Get the data value at the lastIndex()
Definition DirectProductArray.hpp:530
const type_info & getType() const override
Return the element type of the certain array.
Definition DirectProductArray.hpp:496
RefPtr< MemCore::TypedChunk< T > > myChunk() const override
Procedural arrays return a NullPtr here.
Definition DirectProductArray.hpp:514
T first() const override
Get the data value at the firstIndex()
Definition DirectProductArray.hpp:524
RefPtr< MemBase > copy(const MemBase::Creator_t &C=nullptr) const override
Create a copy of the current array, duplicating all data and allocating new memory for it.
Definition DirectProductArray.hpp:441
const CreativeIterator< T > * creativeIterator() const override
Procedural arrays return 0 here.
Definition DirectProductArray.hpp:508
RefPtr< MemBase > makeMemArray(const MemBase::Creator_t &C) const override
Create an actual memory-occupying array from the procedural data here.
Definition DirectProductArray.hpp:450
Description of types, which is meta-information like what is the number of elements of some array-lik...
Definition FiberType.hpp:61
static WeakPtr_t getFiberType()
Get the fiber type information for the current type.
Definition FiberType.hpp:126
A set of integer values which describes how to iterate over a certain set of values.
Definition HyperslabParameters.hpp:34
Convenience class - a Direct Product array which uses linear expressions for each index dimension.
Definition DirectProductArray.hpp:552
bool getNearestMultiIndex(const T &pos, MultiIndex< MDIMS > &index) const
Get an index of the linear array (MultiIndex) from a given global float coordinate.
Definition DirectProductArray.hpp:685
T::value_type component_type
The components of the structured type T.
Definition DirectProductArray.hpp:567
bool getFlooredMultiIndex(const T &pos, MultiIndex< MDIMS > &index) const
Get an index of the linear array (MultiIndex) from a given global float coordinate.
Definition DirectProductArray.hpp:647
const void * OriginPtr() const override
Get pointer to origin of linearly procedural array, if it is linear.
Definition DirectProductArray.hpp:576
LinearDirectProductMemArray(const MultiIndex< MDIMS > &dims, const T &base, const DeltaT &delta, const MemBase::Creator_t &C=MemCore::NullPtr())
Constructor via multidimensional array with base and delta information on the field/array data values...
Definition DirectProductArray.hpp:609
const void * DeltaPtr() const override
Get pointer to delta of linearly procedural array, if it is linear.
Definition DirectProductArray.hpp:577
LinearDirectProductMemArray(const index_t dims[MDIMS], const T &base, const DeltaT &delta, const MemBase::Creator_t &C=MemCore::NullPtr())
Constructor, initializes the Components members.
Definition DirectProductArray.hpp:590
Abstract class for N-dimensional MultiArrays with MemCore memory management.
Definition MemArrayBase.hpp:37
Base class for multidimensional arrays with MemCore memory management.
Definition MemBase.hpp:70
An intermediate class that allows to operate on the pure type information of some memory array.
Definition TypedArray.hpp:58
MemSizeConfig< sizeof(void *)>::memsize_t memsize_t
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
IndexTypeConfig< sizeof(void *)>::index_t index_t
Define the index type as according to the size of a pointer, i.e.
Definition Index.hpp:22
std::nullptr_t NullPtr
StrongPtr< Object, ObjectBase > RefPtr
string to_string(const Eagle::FixedArray< ElementType, N > &A, const char *OpenBrace="{", const char *CloseBrace="}", const char *Separator=",")
Definition DirectProductArray.hpp:360
Definition CoordinateAxisArray.hpp:18