OpendTect  6.6
arrayndimpl.h
Go to the documentation of this file.
1 #pragma once
2 /*
3 ________________________________________________________________________
4 
5  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
6  Author: K. Tingdahl
7  Date: 9-3-1999
8  RCS: $Id$
9 ________________________________________________________________________
10 
11 */
12 
13 
14 #include "arraynd.h"
15 
16 #ifdef __debug__
17 # include "debug.h"
18 #endif
19 
22 template <class T>
24 {
25 protected:
26  virtual od_int64 getStorageSize() const = 0;
27 
29  ~ArrayImplBase() { delete stor_; }
30 
31  bool storageOK() const;
38  bool getDataFrom(const ArrayND<T>& templ);
39 
41  T* ptr_; //not owned, only a shortcut
42  //for the 99% percent case
43 };
44 
45 
50 template <class T>
53 public:
54 
55  Array1DImpl(int sz);
58  Array1DImpl<T>& operator =( const Array1D<T>& ai )
59  { copyFrom(ai); return *this; }
60  Array1DImpl<T>& operator =( const Array1DImpl<T>& ai )
61  { copyFrom(ai); return *this; }
62 
64  { return new Array1DImpl<T>(*this); }
65 
66  bool isOK() const { return base::storageOK(); }
67  void copyFrom(const Array1D<T>&);
69  { return base::setStorageInternal(vs); }
70  bool canSetStorage() const { return true; }
71 
72  void set(int pos,T);
73  T get(int pos) const;
74 
75  const Array1DInfo& info() const { return in_; }
76  bool canSetInfo() const { return true; }
77  bool setInfo(const ArrayNDInfo&);
78  bool setSize(int);
79  bool setSize( od_int64 sz )
80  { return setSize( ((int)sz) ); }
81 
82  // ValueSeries interface
83  T* arr() { return base::ptr_; }
84  const T* arr() const { return base::ptr_; }
85 
86 protected:
87  const T* getData_() const { return base::ptr_; }
88  const ValueSeries<T>* getStorage_() const { return base::stor_; }
89  od_int64 getStorageSize() const { return in_.getTotalSz(); }
90 
92 
93 };
94 
95 
100 template <class T>
103 public:
104  Array2DImpl(int sz0,int sz1);
109 
110  Array2DImpl<T>& operator =( const Array2D<T>& ai )
111  { copyFrom(ai); return *this; }
112  Array2DImpl<T>& operator =( const Array2DImpl<T>& ai )
113  { copyFrom(ai); return *this; }
114 
115  bool isOK() const { return base::storageOK(); }
116  bool canSetStorage() const { return true; }
118 
119  void set(int,int,T);
120  T get(int,int) const;
121  void copyFrom(const Array2D<T>&);
122 
123  const Array2DInfo& info() const { return in_; }
124  bool canSetInfo() const { return true; }
125 
126  bool setInfo(const ArrayNDInfo&);
127  bool setSize(int,int);
128 
129  T** get2DData() { return ptr2d_; }
130  const T** get2DData() const { return (const T**) ptr2d_; }
131 
132 protected:
134  const T* getData_() const { return base::ptr_; }
135  const ValueSeries<T>* getStorage_() const { return base::stor_; }
136  od_int64 getStorageSize() const { return in_.getTotalSz(); }
137 
139 
141  T** ptr2d_;
142 };
143 
144 
149 template <class T>
152 public:
153  Array3DImpl(int sz0,int sz1,int sz2);
157  ~Array3DImpl() { eraseCache(); }
158  Array3DImpl<T>& operator =( const Array3D<T>& ai )
159  { copyFrom(ai); return *this; }
160  Array3DImpl<T>& operator =( const Array3DImpl<T>& ai )
161  { copyFrom(ai); return *this; }
162 
163  bool isOK() const { return base::storageOK(); }
164  bool canSetStorage() const { return true; }
166 
167  void set(int,int,int,T);
168  T get(int,int,int) const;
169  void copyFrom(const Array3D<T>&);
170 
171  const Array3DInfo& info() const { return in_; }
172  bool canSetInfo() const { return true; }
173  bool setInfo(const ArrayNDInfo&);
174  bool setSize(int,int,int);
175 
176  T*** get3DData() { return ptr3d_; }
177  const T*** get3DData() const { return (const T***) ptr3d_; }
178 
179 protected:
181  const T* getData_() const { return base::ptr_; }
182  const ValueSeries<T>* getStorage_() const { return base::stor_; }
183  od_int64 getStorageSize() const { return in_.getTotalSz(); }
184 
186  void eraseCache();
187 
189  T*** ptr3d_;
191 };
192 
193 
196 template <class T>
199 public:
200  Array4DImpl(int,int,int,int);
201  Array4DImpl(const Array4DInfo&);
202  Array4DImpl(const Array4D<T>&);
203  Array4DImpl(const Array4DImpl<T>&);
204  ~Array4DImpl() { eraseCache(); }
205  Array4DImpl<T>& operator =( const Array4D<T>& ai )
206  { copyFrom(ai); return *this; }
207  Array4DImpl<T>& operator =( const Array4DImpl<T>& ai )
208  { copyFrom(ai); return *this; }
209 
210  bool isOK() const { return base::storageOK(); }
211  bool canSetStorage() const { return true; }
212  bool setStorage(ValueSeries<T>* vs);
213 
214  void set(int,int,int,int,T);
215  T get(int,int,int,int) const;
216  void copyFrom(const Array4D<T>&);
217 
218  const Array4DInfo& info() const { return inf_; }
219  bool canSetInfo() const { return true; }
220  bool setInfo(const ArrayNDInfo&);
221  bool setSize(int,int,int,int);
222 
223  T**** get4DData() { return arr4d_; }
224  const T**** get4DData() const { return (const T****)arr4d_; }
225 
226 protected:
227 
228  void updateStorage();
229  const T* getData_() const { return base::ptr_; }
230  const ValueSeries<T>* getStorage_() const { return base::stor_; }
231  od_int64 getStorageSize() const { return inf_.totalSize(); }
232 
233  void updateCachePointers();
234  void eraseCache();
235 
237  T**** arr4d_;
239 };
240 
241 
246 mGlobal(Basic) void* getArrayND(const ArrayNDInfo&,const OD::DataRepType);
247 
248 template <class T>
251 public:
252 
253  static ArrayND<T>* create(const ArrayNDInfo& nsz);
254  static ArrayND<T>* clone(const ArrayND<T>&);
255  static bool clone(const ArrayND<T>&,ArrayND<T>&);
256 
260  ArrayNDImpl<T>& operator =( const ArrayND<T>& ai )
261  { copyFrom(ai); return *this; }
262  ArrayNDImpl<T>& operator =( const ArrayNDImpl<T>& ai )
263  { copyFrom(ai); return *this; }
265 
266  bool isOK() const { return base::storageOK(); }
267  bool canSetStorage() const { return true; }
269  { return base::setStorageInternal(vs); }
270 
271  void setND(const int*,T);
272  T getND(const int*) const;
273 
274  const ArrayNDInfo& info() const { return *in_; }
275  bool canSetInfo() const { return true; }
276  bool canChangeNrDims() const { return true; }
277  bool setInfo(const ArrayNDInfo&);
278 
279  bool setSize(const int*);
280  void copyFrom(const ArrayND<T>&);
281 
282 protected:
283 
284  const T* getData_() const { return base::ptr_; }
285  const ValueSeries<T>* getStorage_() const { return base::stor_; }
286  od_int64 getStorageSize() const { return in_->getTotalSz(); }
287 
289 };
290 
291 
292 template <class T> inline
294  : stor_(0)
295  , ptr_(0)
296 { }
297 
298 
299 template <class T> inline
301 {
302  ptr_ = 0;
303  delete stor_;
304 
305  stor_ = s;
306 
307  ptr_ = stor_->arr();
308 
309  return true;
310 }
311 
312 
313 template <class T> inline
315 {
316  ptr_ = 0;
317  if ( !s->setSize(getStorageSize()) )
318  {
319  delete s;
320  return false;
321  }
322 
323  return setStorageNoResize( s );
324 }
325 
326 
327 template <class T> inline
329 {
330  if ( !stor_ )
331  {
332  setStorageNoResize(
333  new MultiArrayValueSeries<T,T>(getStorageSize()));
334  }
335 
336  if ( !stor_ || !stor_->setSize( getStorageSize() ) )
337  {
338  ptr_ = 0;
339  delete stor_;
340  stor_ = 0;
341  return false;
342  }
343 
344  ptr_ = stor_->arr();
345  return true;
346 }
347 
348 
349 template <class T> inline
351 { return stor_ && stor_->isOK(); }
352 
353 
354 template <class T> inline
356 {
357  if ( !storageOK() )
358  return false;
359 
360  if ( ptr_ )
361  {
362  templ.getAll( ptr_ );
363  return true;
364  }
365 
366  if ( stor_ )
367  {
368  templ.getAll( *stor_ );
369  return true;
370  }
371 
372  if ( getStorageSize() )
373  {
374  pErrMsg("Cannot store in array without storage" );
375  return false;
376  }
377 
378  return true;
379 }
380 
381 
382 template <class T> inline
384  : in_(nsz)
385 {
387 }
388 
389 
390 template <class T> inline
392  : in_(templ.info())
393 {
395  copyFrom( templ );
396 }
397 
398 
399 template <class T> inline
401  : in_(templ.info())
402 {
404  copyFrom( templ );
405 }
406 
407 
408 template <class T> inline
409 void Array1DImpl<T>::set( int pos, T v )
410 {
411 #ifdef __debug__
412  if ( !in_.validPos( pos ) )
413  { pErrMsg("Invalid access"); DBG::forceCrash(true); }
414 #endif
415  if ( base::ptr_ ) base::ptr_[pos] = v;
416  else base::stor_->setValue(pos,v);
417 }
418 
419 
420 template <class T> inline
421 T Array1DImpl<T>::get( int pos ) const
422 {
423 #ifdef __debug__
424  if ( !in_.validPos( pos ) )
425  { pErrMsg("Invalid access"); DBG::forceCrash(true); }
426 #endif
427  return base::ptr_ ? base::ptr_[pos] : base::stor_->value(pos);
428 }
429 
430 
431 template <class T> inline
433 {
434  if ( in_ != templ.info() )
435  setInfo( templ.info() );
436 
437  base::getDataFrom( templ );
438 }
439 
440 
441 template <class T> inline
443 {
444  if ( ni.getNDim() != 1 ) return false;
445  return setSize( ni.getSize(0) );
446 }
447 
448 
449 template <class T> inline
451 {
452  in_.setSize( 0, s );
453  base::updateStorageSize();
454  return true;
455 }
456 
457 
458 template <class T> inline
459 Array2DImpl<T>::Array2DImpl( int sz0, int sz1 )
460  : in_(sz0,sz1)
461  , ptr2d_(0)
462 {
463  updateStorage();
464 }
465 
466 
467 template <class T> inline
469  : in_( nsz )
470  , ptr2d_(0)
471 {
472  updateStorage();
473 }
474 
475 
476 template <class T> inline
478  : in_(templ.info())
479  , ptr2d_(0)
480 {
481  updateStorage();
482  copyFrom( templ );
483 }
484 
485 
486 template <class T> inline
488  : in_(templ.info())
489  , ptr2d_(0)
490 {
491  updateStorage();
492  copyFrom( templ );
493 }
494 
495 
496 template <class T> inline
497 void Array2DImpl<T>::set( int p0, int p1, T v )
498 {
499 #ifdef __debug__
500  if ( !in_.validPos( p0, p1 ) )
501  {
502  pErrMsg("Invalid access");
503  DBG::forceCrash(true);
504  }
505 #endif
506  if ( ptr2d_ )
507  {
508  ptr2d_[p0][p1] = v;
509  }
510  else
511  {
512  const od_int64 offset = in_.getOffset( p0, p1 );
513  base::stor_->setValue( offset, v );
514  }
515 }
516 
517 
518 template <class T> inline
519 T Array2DImpl<T>::get( int p0, int p1 ) const
520 {
521 #ifdef __debug__
522  if ( !in_.validPos( p0, p1 ) )
523  {
524  pErrMsg("Invalid access");
525  DBG::forceCrash(true);
526  }
527 #endif
528 
529  if ( ptr2d_ )
530  return ptr2d_[p0][p1];
531 
532  const od_int64 offset = in_.getOffset( p0, p1 );
533  return base::stor_->value( offset );
534 }
535 
536 
537 template <class T> inline
539 {
540  bool res = base::setStorageInternal(vs);
541  updateCachePointers();
542  return res;
543 }
544 
545 
546 template <class T> inline
548 {
549  if ( in_ != templ.info() )
550  setInfo( templ.info() );
551 
552  base::getDataFrom( templ );
553 }
554 
555 
556 template <class T> inline
558 {
559  if ( ni.getNDim() != 2 ) return false;
560  return setSize( ni.getSize(0), ni.getSize(1) );
561 }
562 
563 
564 template <class T> inline
565 bool Array2DImpl<T>::setSize( int d0, int d1 )
566 {
567  in_.setSize( 0, d0 ); in_.setSize( 1, d1 );
568  updateStorage();
569  return true;
570 }
571 
572 
573 template <class T> inline
575 {
576  base::updateStorageSize();
577  updateCachePointers();
578 }
579 
580 
581 template <class T> inline
583 {
584  deleteAndZeroArrPtr( ptr2d_ );
585 
586  if ( !base::ptr_ )
587  return;
588 
589  const int n1 = in_.getSize( 0 );
590  mTryAlloc(ptr2d_,T*[n1])
591  if ( !ptr2d_ )
592  return;
593 
594  const int n2 = in_.getSize( 1 );
595  od_uint64 offset = 0;
596  for ( int idx=0; idx<n1; idx++, offset+=n2 )
597  ptr2d_[idx] = base::ptr_ + offset;
598 }
599 
600 
601 template <class T> inline
602 Array3DImpl<T>::Array3DImpl( int sz0, int sz1, int sz2 )
603  : in_(sz0,sz1,sz2)
604  , ptr3d_(0)
605 {
606  updateStorage();
607 }
608 
609 
610 template <class T> inline
612  : in_(nsz)
613  , ptr3d_(0)
614 {
615  updateStorage();
616 }
617 
618 
619 template <class T> inline
621  : in_(templ.info())
622  , ptr3d_(0)
623 {
624  updateStorage();
625  copyFrom( templ );
626 }
627 
628 
629 template <class T> inline
631  : in_(templ.info())
632  , ptr3d_(0)
633 {
634  updateStorage();
635  copyFrom( templ );
636 }
637 
638 
639 template <class T> inline
640 void Array3DImpl<T>::set( int p0, int p1, int p2, T v )
641 {
642 #ifdef __debug__
643  if ( !in_.validPos( p0, p1, p2 ) )
644  { pErrMsg("Invalid access"); DBG::forceCrash(true); }
645 #endif
646  if ( ptr3d_ )
647  {
648  ptr3d_[p0][p1][p2] = v;
649  }
650  else
651  {
652  const od_int64 offset = in_.getOffset( p0, p1, p2 );
653  base::stor_->setValue( offset, v );
654  }
655 }
656 
657 
658 template <class T> inline
659 T Array3DImpl<T>::get( int p0, int p1, int p2 ) const
660 {
661 #ifdef __debug__
662  if ( !in_.validPos( p0, p1, p2 ) )
663  { pErrMsg("Invalid access"); DBG::forceCrash(true); }
664 #endif
665  if ( ptr3d_ )
666  return ptr3d_[p0][p1][p2];
667 
668  const od_int64 offset = in_.getOffset( p0, p1, p2 );
669  return base::stor_->value( offset );
670 }
671 
672 
673 template <class T> inline
675 {
676  if ( in_ != templ.info() )
677  setInfo( templ.info() );
678 
679  base::getDataFrom( templ );
680 }
681 
682 
683 template <class T> inline
685 {
686  bool res = base::setStorageInternal(vs);
687  updateCachePointers();
688  return res;
689 }
690 
691 template <class T> inline
693 {
694  if ( ni.getNDim() != 3 ) return false;
695  return setSize( ni.getSize(0), ni.getSize(1), ni.getSize(2) );
696 }
697 
698 
699 template <class T> inline
700 bool Array3DImpl<T>::setSize( int d0, int d1, int d2 )
701 {
702  in_.setSize( 0, d0 ); in_.setSize( 1, d1 ); in_.setSize( 2, d2 );
703  updateStorage();
704  return true;
705 }
706 
707 
708 template <class T> inline
710 {
711  base::updateStorageSize();
712  updateCachePointers();
713 }
714 
715 
716 template <class T> inline
718 {
719  for ( int idx=0; idx<cachestor_.size(); idx++ )
720  {
721  delete [] cachestor_[idx];
722  }
723 
724  cachestor_.erase();
725  ptr3d_ = 0;
726 }
727 
728 
729 template <class T> inline
731 {
732  eraseCache();
733 
734  if ( !base::ptr_ )
735  return;
736 
737  const int n1 = in_.getSize( 0 );
738  const int n2 = in_.getSize( 1 );
739  const int n3 = in_.getSize( 2 );
740  od_uint64 offset = 0;
741  for ( int idx=0; idx<n1; idx++ )
742  {
743  mDeclareAndTryAlloc(T**,ptr2d,T*[n2])
744  if ( !ptr2d )
745  return;
746 
747  for ( int idy=0; idy<n2; idy++, offset+=n3 )
748  ptr2d[idy] = base::ptr_ + offset;
749 
750  cachestor_ += ptr2d;
751  }
752 
753  ptr3d_ = &cachestor_[0];
754 }
755 
756 
757 //Array4DImpl---
758 
759 template <class T> inline
760 Array4DImpl<T>::Array4DImpl( int sz0, int sz1, int sz2,
761  int sz3 )
762  : inf_(sz0,sz1,sz2,sz3)
763  , arr4d_(0)
764 {
765  updateStorage();
766 }
767 
768 
769 template <class T> inline
771  : inf_(nsz)
772  , arr4d_(0)
773 {
774  updateStorage();
775 }
776 
777 
778 template <class T> inline
780  : inf_(templ.info())
781  , arr4d_(0)
782 {
783  updateStorage();
784  copyFrom( templ );
785 }
786 
787 
788 template <class T> inline
790  : inf_(templ.info())
791  , arr4d_(0)
792 {
793  updateStorage();
794  copyFrom( templ );
795 }
796 
797 
798 template <class T> inline
799 void Array4DImpl<T>::set( int p0, int p1, int p2, int p3,
800  T v )
801 {
802 #ifdef __debug__
803  if ( !inf_.validPos( p0, p1, p2, p3 ) )
804  { pErrMsg("Invalid access"); DBG::forceCrash(true); }
805 #endif
806  if ( arr4d_ )
807  arr4d_[p0][p1][p2][p3] = v;
808  else
809  {
810  const od_uint64 offset = inf_.getOffset( p0, p1, p2, p3 );
811  base::stor_->setValue( offset, v );
812  }
813 }
814 
815 
816 template <class T> inline
817 T Array4DImpl<T>::get( int p0, int p1, int p2,
818  int p3 ) const
819 {
820 #ifdef __debug__
821  if ( !inf_.validPos( p0, p1, p2, p3 ) )
822  { pErrMsg("Invalid access"); DBG::forceCrash(true); }
823 #endif
824  if ( arr4d_ )
825  return arr4d_[p0][p1][p2][p3];
826 
827  const od_uint64 offset = inf_.getOffset( p0, p1, p2, p3 );
828  return base::stor_->value( offset );
829 }
830 
831 
832 template <class T> inline
834 {
835  if ( inf_ != templ.info() )
836  setInfo( templ.info() );
837 
838  base::getDataFrom( templ );
839 }
840 
841 
842 template <class T> inline
844 {
845  bool res = base::setStorageInternal(vs);
846  updateCachePointers();
847  return res;
848 }
849 
850 template <class T> inline
852 {
853  if ( ni.nrDims() != 4 )
854  return false;
855  return setSize( ni.getSize(0), ni.getSize(1), ni.getSize(2), ni.getSize(3));
856 }
857 
858 
859 template <class T> inline
860 bool Array4DImpl<T>::setSize( int d0, int d1, int d2,
861  int d3 )
862 {
863  inf_.setSize( 0, d0 ); inf_.setSize( 1, d1 );
864  inf_.setSize( 2, d2 ); inf_.setSize( 3, d3 );
865  updateStorage();
866  return true;
867 }
868 
869 
870 template <class T> inline
872 {
873  base::updateStorageSize();
874  updateCachePointers();
875 }
876 
877 
878 template <class T> inline
880 {
881  const int n2 = inf_.getSize( 1 );
882  for ( int idx=0; idx<cachestor_.size(); idx++ )
883  {
884  T*** cachestoridx = cachestor_[idx];
885  for ( int idy=0; idy<n2; idy++ )
886  delete [] cachestoridx[idy];
887  delete [] cachestoridx;
888  }
889 
890  cachestor_.erase();
891  arr4d_ = 0;
892 }
893 
894 
895 template <class T> inline
897 {
898  eraseCache();
899 
900  if ( !base::ptr_ )
901  return;
902 
903  const int n1 = inf_.getSize( 0 );
904  const int n2 = inf_.getSize( 1 );
905  const int n3 = inf_.getSize( 2 );
906  const int n4 = inf_.getSize( 3 );
907  od_uint64 offset = 0;
908  for ( int idx=0; idx<n1; idx++ )
909  {
910  mDeclareAndTryAlloc(T***,ptr3d,T**[n2])
911  if ( !ptr3d )
912  return;
913 
914  for ( int idy=0; idy<n2; idy++ )
915  {
916  mDeclareAndTryAlloc(T**,ptr2d,T*[n3])
917  if ( !ptr2d )
918  return;
919 
920  for ( int idz=0; idz<n3; idz++, offset+=n4 )
921  ptr2d[idz] = base::ptr_ + offset;
922 
923  ptr3d[idy] = ptr2d;
924  }
925 
926  cachestor_ += ptr3d;
927  }
928 
929  arr4d_ = &cachestor_[0];
930 }
931 
932 
933 template <class T> inline
935  : in_(nsz.clone())
936 {
938 }
939 
940 
941 template <class T> inline
943  : in_( templ.info().clone() )
944 {
946  copyFrom( templ );
947 }
948 
949 
950 template <class T> inline
952  : in_( templ.info().clone() )
953 {
955  copyFrom( templ );
956 }
957 
958 
959 template <class T> inline ArrayNDImpl<T>::~ArrayNDImpl()
960 { delete in_; }
961 
962 
963 template <class T> inline
965 {
966  if ( info()!=templ.info() )
967  {
968  delete in_;
969  in_ = templ.info().clone();
970  }
971 
972  base::getDataFrom( templ );
973 }
974 
975 
976 template <class T> inline
977 void ArrayNDImpl<T>::setND( const int* pos, T v )
978 {
979 #ifdef __debug__
980  if ( !in_->validPos( pos ) )
981  { pErrMsg("Invalid access"); DBG::forceCrash(true); }
982 #endif
983  const od_int64 offset = in_->getOffset(pos);
984  if ( base::ptr_ ) base::ptr_[offset] = v ;
985  else base::stor_->setValue( offset, v);
986 }
987 
988 
989 template <class T> inline
990 T ArrayNDImpl<T>::getND( const int* pos ) const
991 {
992 #ifdef __debug__
993  if ( !in_->validPos( pos ) )
994  { pErrMsg("Invalid access"); DBG::forceCrash(true); }
995 #endif
996  const od_int64 offset = in_->getOffset(pos);
997  return base::ptr_ ? base::ptr_[offset] : base::stor_->value( offset );
998 }
999 
1000 
1001 template <class T> inline
1003 {
1004  if ( ni.getNDim() != in_->getNDim() )
1005  return false;
1006 
1007  const int ndim = in_->getNDim();
1008  TypeSet<int> sizes( ndim, 0 );
1009  for ( int idx=0; idx<ndim; idx++ )
1010  sizes[idx] = ni.getSize(idx);
1011 
1012  return setSize( sizes.arr() );
1013 }
1014 
1015 
1016 template <class T> inline
1017 bool ArrayNDImpl<T>::setSize( const int* d )
1018 {
1019  const int ndim = in_->getNDim();
1020  for ( int idx=0; idx<ndim; idx++ )
1021  in_->setSize( idx, d[idx] );
1022 
1023  base::updateStorageSize();
1024  return true;
1025 }
1026 
1027 
1028 template <class T> inline
1030 {
1031  int ndim = nsz.getNDim();
1032 
1033  if ( ndim==1 ) return new Array1DImpl<T>( nsz.getSize(0) );
1034  if ( ndim==2 ) return new Array2DImpl<T>( nsz.getSize(0), nsz.getSize(1) );
1035  if ( ndim==3 ) return new Array3DImpl<T>( nsz.getSize(0), nsz.getSize(1),
1036  nsz.getSize(2) );
1037  if ( ndim==4 )
1038  return new Array4DImpl<T>( nsz.getSize(0), nsz.getSize(1),
1039  nsz.getSize(2), nsz.getSize(3) );
1040 
1041  return new ArrayNDImpl<T>( nsz );
1042 }
1043 
1044 
1045 template <class T> inline
1047 {
1048  ArrayND<T>* out = create( oth.info() );
1049  if ( !out )
1050  return 0;
1051 
1052  if ( !out->isOK() )
1053  { delete out; return 0; }
1054 
1055  const bool success = clone( oth, *out );
1056  if ( !success )
1057  { delete out; return 0; }
1058 
1059  return out;
1060 }
1061 
1062 
1063 template <class T> inline
1065 {
1066  const od_uint64 sz = inp.info().getTotalSz();
1067  if ( !inp.isOK() )
1068  return false;
1069 
1070  if ( !out.isOK() || out.info() != inp.info() )
1071  {
1072  if ( !out.setInfo(inp.info()) ) //Also allocates storage
1073  return false;
1074  }
1075 
1076  if ( inp.getData() && out.getData() )
1077  {
1078  OD::memCopy( out.getData(), inp.getData(), sz*sizeof(T) );
1079  return true;
1080  }
1081 
1082  const int ndim = inp.info().getNDim();
1083  if ( ndim==1 )
1084  {
1085  mDynamicCastGet(const Array1DImpl<T>*,inp1d,&inp)
1086  mDynamicCastGet(Array1DImpl<T>*,out1d,&out)
1087  if ( inp1d && out1d )
1088  { *out1d = *inp1d; return true; }
1089  }
1090  else if ( ndim==2 )
1091  {
1092  mDynamicCastGet(const Array2DImpl<T>*,inp2d,&inp)
1093  mDynamicCastGet(Array2DImpl<T>*,out2d,&out)
1094  if ( inp2d && out2d )
1095  { *out2d = *inp2d; return true; }
1096  }
1097  else if ( ndim==3 )
1098  {
1099  mDynamicCastGet(const Array3DImpl<T>*,inp3d,&inp)
1100  mDynamicCastGet(Array3DImpl<T>*,out3d,&out)
1101  if ( inp3d && out3d )
1102  { *out3d = *inp3d; return true; }
1103  }
1104  else if ( ndim == 4 )
1105  {
1106  mDynamicCastGet(const Array4DImpl<T>*,inp4d,&inp)
1107  mDynamicCastGet(Array4DImpl<T>*,out4d,&out)
1108  if ( inp4d && out4d )
1109  { *out4d = *inp4d; return true; }
1110  }
1111 
1112  mDynamicCastGet(const ArrayNDImpl<T>*,inpnd,&inp)
1113  mDynamicCastGet(ArrayNDImpl<T>*,outnd,&out)
1114  if ( inpnd && outnd )
1115  {
1116  *outnd = *inpnd;
1117  return true;
1118  }
1119 
1120  ValueSeries<T>* newstor = out.getStorage();
1121  if ( newstor )
1122  {
1123  inp.getAll( *newstor );
1124  return true;
1125  }
1126 
1127  ArrayNDIter iter( inp.info() );
1128  do
1129  {
1130  const int* pos = iter.getPos();
1131  out.setND( pos, inp.getND(pos) );
1132  } while ( iter.next() );
1133 
1134  return true;
1135 }
1136 
ValueSeries
Interface to a series of values.
Definition: odmemory.h:16
od_uint64
#define od_uint64
Definition: plftypes.h:36
ArrayNDImpl::ArrayNDImpl
ArrayNDImpl(const ArrayND< T > &)
Definition: arrayndimpl.h:942
Array4DImpl::arr4d_
T **** arr4d_
Definition: arrayndimpl.h:237
Array2DImpl::canSetInfo
bool canSetInfo() const
Definition: arrayndimpl.h:124
Array3DImpl::updateCachePointers
void updateCachePointers()
Definition: arrayndimpl.h:730
Array4D
4-Dim ArrayND
Definition: arraynd.h:183
Array2DImpl::base
ArrayImplBase< T > base
Definition: arrayndimpl.h:102
ArrayNDImpl::isOK
bool isOK() const
Definition: arrayndimpl.h:266
Array2DImpl::get2DData
const T ** get2DData() const
Definition: arrayndimpl.h:130
Array3DImpl::set
void set(int, int, int, T)
Definition: arrayndimpl.h:640
Array1DImpl::isOK
bool isOK() const
Definition: arrayndimpl.h:66
Array3DImpl::Array3DImpl
Array3DImpl(const Array3DInfo &)
Definition: arrayndimpl.h:611
Array4DImpl::setInfo
bool setInfo(const ArrayNDInfo &)
Definition: arrayndimpl.h:851
Array2DInfo
Contains the information about the size of Array2D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:124
ArrayNDImpl::create
static ArrayND< T > * create(const ArrayNDInfo &nsz)
Definition: arrayndimpl.h:1029
Array1DImpl::info
const Array1DInfo & info() const
Definition: arrayndimpl.h:75
ArrayImplBase::ArrayImplBase
ArrayImplBase()
Definition: arrayndimpl.h:293
Array3DImpl::get
T get(int, int, int) const
Definition: arrayndimpl.h:659
ArrayNDImpl::setND
void setND(const int *, T)
Definition: arrayndimpl.h:977
ArrayNDInfo
Contains the information about the size of ArrayND, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:25
mGlobal
#define mGlobal(module)
Definition: commondefs.h:180
Array2DImpl::ptr2d_
T ** ptr2d_
Definition: arrayndimpl.h:141
ArrayNDImpl::ArrayNDImpl
ArrayNDImpl(const ArrayNDImpl< T > &)
Definition: arrayndimpl.h:951
ArrayNDInfo::getTotalSz
virtual uint64_t getTotalSz() const
Array4DImpl::isOK
bool isOK() const
Definition: arrayndimpl.h:210
MultiArrayValueSeries
Valueseries that allocates its data in smaller chunks. By doing this, it performs better in environme...
Definition: valseries.h:159
Array2DImpl::getData_
const T * getData_() const
Definition: arrayndimpl.h:134
Array2DImpl::canSetStorage
bool canSetStorage() const
Definition: arrayndimpl.h:116
ArrayImplBase::getStorageSize
virtual int64_t getStorageSize() const =0
Array1DImpl
Implementation of Array1D.
Definition: arrayndimpl.h:52
getArrayND
void * getArrayND(const ArrayNDInfo &, const OD::DataRepType)
Implementation of ArrayND.
od_int64
#define od_int64
Definition: plftypes.h:35
Array3DImpl::updateStorage
void updateStorage()
Definition: arrayndimpl.h:709
Array2DImpl::info
const Array2DInfo & info() const
Definition: arrayndimpl.h:123
Array3DImpl::setSize
bool setSize(int, int, int)
Definition: arrayndimpl.h:700
Array4DImpl
Flat-array implementation of Array4D.
Definition: arrayndimpl.h:198
ArrayNDImpl::ArrayNDImpl
ArrayNDImpl(const ArrayNDInfo &)
Definition: arrayndimpl.h:934
Array3DImpl::Array3DImpl
Array3DImpl(const Array3DImpl< T > &)
Definition: arrayndimpl.h:630
Array4DImpl::getData_
const T * getData_() const
Definition: arrayndimpl.h:229
Array1DImpl::Array1DImpl
Array1DImpl(int sz)
Definition: arrayndimpl.h:383
Array3D::info
virtual const Array3DInfo & info() const =0
ValueSeries::setSize
virtual bool setSize(int64_t)
Definition: valseries.h:53
Array3DImpl::info
const Array3DInfo & info() const
Definition: arrayndimpl.h:171
ArrayImplBase::~ArrayImplBase
~ArrayImplBase()
Definition: arrayndimpl.h:29
Array1DImpl::arr
T * arr()
Definition: arrayndimpl.h:83
Array3DImpl
Implementation of Array3D.
Definition: arrayndimpl.h:151
Array3DImpl::isOK
bool isOK() const
Definition: arrayndimpl.h:163
Array2DImpl::updateCachePointers
void updateCachePointers()
Definition: arrayndimpl.h:582
mDynamicCastGet
#define mDynamicCastGet(typ, out, in)
Definition: commondefs.h:148
Array2DImpl::get2DData
T ** get2DData()
Definition: arrayndimpl.h:129
ArrayNDInfo::getSize
virtual int getSize(int dim) const =0
Array3DImpl::canSetInfo
bool canSetInfo() const
Definition: arrayndimpl.h:172
Array4DImpl::Array4DImpl
Array4DImpl(int, int, int, int)
Definition: arrayndimpl.h:760
Array4DImpl::setStorage
bool setStorage(ValueSeries< T > *vs)
Definition: arrayndimpl.h:843
ArrayND::getStorage
const ValueSeries< T > * getStorage() const
Definition: arraynd.h:45
Array4D::info
virtual const Array4DInfo & info() const =0
Array3DImpl::in_
Array3DInfoImpl in_
Definition: arrayndimpl.h:190
ArrayImplBase::updateStorageSize
bool updateStorageSize()
Definition: arrayndimpl.h:328
Array1D
Array1D ( Subclass of ArrayND ) is a one dimensional array.
Definition: arraynd.h:111
Array2DImpl::setInfo
bool setInfo(const ArrayNDInfo &)
Definition: arrayndimpl.h:557
ArrayNDImpl::getData_
const T * getData_() const
Definition: arrayndimpl.h:284
Array3DImpl::canSetStorage
bool canSetStorage() const
Definition: arrayndimpl.h:164
ArrayND::isOK
virtual bool isOK() const
Definition: arraynd.h:367
Array1D::info
virtual const Array1DInfo & info() const =0
ArrayND::setND
virtual void setND(const int *, T)=0
Array4DImpl::info
const Array4DInfo & info() const
Definition: arrayndimpl.h:218
Array2DImpl::Array2DImpl
Array2DImpl(int sz0, int sz1)
Definition: arrayndimpl.h:459
Array4DImpl::setSize
bool setSize(int, int, int, int)
Definition: arrayndimpl.h:860
ArrayImplBase::getDataFrom
bool getDataFrom(const ArrayND< T > &templ)
Definition: arrayndimpl.h:355
Array1DImpl::set
void set(int pos, T)
Definition: arrayndimpl.h:409
arraynd.h
Array3DImpl::Array3DImpl
Array3DImpl(int sz0, int sz1, int sz2)
Definition: arrayndimpl.h:602
Array4DImpl::getStorage_
const ValueSeries< T > * getStorage_() const
Definition: arrayndimpl.h:230
Array3D
Array3D ( Subclass of ArrayND ) is a three dimensional array.
Definition: arraynd.h:162
ArrayNDImpl::clone
static ArrayND< T > * clone(const ArrayND< T > &)
Definition: arrayndimpl.h:1046
ArrayND::info
virtual const ArrayNDInfo & info() const =0
ArrayImplBase::setStorageNoResize
bool setStorageNoResize(ValueSeries< T > *)
Definition: arrayndimpl.h:300
Array2DImpl::updateStorage
void updateStorage()
Definition: arrayndimpl.h:574
ArrayImplBase::stor_
ValueSeries< T > * stor_
Definition: arrayndimpl.h:40
Array4DImpl::get
T get(int, int, int, int) const
Definition: arrayndimpl.h:817
ArrayNDImpl::getND
T getND(const int *) const
Definition: arrayndimpl.h:990
ArrayNDImpl::info
const ArrayNDInfo & info() const
Definition: arrayndimpl.h:274
mDeclareAndTryAlloc
#define mDeclareAndTryAlloc(tp, var, stmt)
Creates variable, try to alloc and catch bad_alloc.
Definition: commondefs.h:253
ArrayNDImpl
Definition: arrayndimpl.h:250
Array1DImpl::canSetStorage
bool canSetStorage() const
Definition: arrayndimpl.h:70
Array1DImpl::base
ArrayImplBase< T > base
Definition: arrayndimpl.h:52
Array4DImpl::updateCachePointers
void updateCachePointers()
Definition: arrayndimpl.h:896
Array4DImpl::copyFrom
void copyFrom(const Array4D< T > &)
Definition: arrayndimpl.h:833
Array4DImpl::getStorageSize
int64_t getStorageSize() const
Definition: arrayndimpl.h:231
ArrayNDImpl::setInfo
bool setInfo(const ArrayNDInfo &)
Definition: arrayndimpl.h:1002
mClass
#define mClass(module)
Definition: commondefs.h:181
Array2DImpl::setStorage
bool setStorage(ValueSeries< T > *vs)
Definition: arrayndimpl.h:538
Array1DImpl::setSize
bool setSize(int)
Definition: arrayndimpl.h:450
deleteAndZeroArrPtr
void deleteAndZeroArrPtr(T *&ptr, bool isowner=true)
Definition: ptrman.h:32
Array1DInfo
Contains the information about the size of Array1D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:100
ArrayNDIter::getPos
const int * getPos() const
Definition: arraynd.h:220
Array4DImpl::set
void set(int, int, int, int, T)
Definition: arrayndimpl.h:799
ArrayNDInfo::nrDims
int nrDims() const
Definition: arrayndinfo.h:41
ArrayNDIter
Iterates through all samples in an ArrayND.
Definition: arraynd.h:209
mTryAlloc
#define mTryAlloc(var, stmt)
Catches bad_alloc and sets ptr to null as normal.
Definition: commondefs.h:246
ArrayNDIter::next
bool next()
Array4DInfo
Contains the information about the size of Array4D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:166
Array4DImpl::canSetStorage
bool canSetStorage() const
Definition: arrayndimpl.h:211
Array3DImpl::copyFrom
void copyFrom(const Array3D< T > &)
Definition: arrayndimpl.h:674
ArrayNDImpl::canChangeNrDims
bool canChangeNrDims() const
Definition: arrayndimpl.h:276
Array2DImpl::isOK
bool isOK() const
Definition: arrayndimpl.h:115
Array1DImpl::getData_
const T * getData_() const
Definition: arrayndimpl.h:87
Array2DImpl::Array2DImpl
Array2DImpl(const Array2D< T > &)
Definition: arrayndimpl.h:477
pErrMsg
#define pErrMsg(msg)
Usual access point for programmer error messages.
Definition: errmsg.h:37
Conv::set
void set(T &_to, const F &fr)
template based type conversion
Definition: convert.h:27
Array3DInfo
Contains the information about the size of Array3D, and in what order the data is stored (if accessab...
Definition: arrayndinfo.h:147
ArrayNDImpl::setSize
bool setSize(const int *)
Definition: arrayndimpl.h:1017
Array3DImpl::eraseCache
void eraseCache()
Definition: arrayndimpl.h:717
Array3DImpl::cachestor_
TypeSet< T ** > cachestor_
Definition: arrayndimpl.h:188
Array3DInfoImpl
Implementation of Array3DInfo.
Definition: arrayndinfo.h:239
Array3DImpl::get3DData
T *** get3DData()
Definition: arrayndimpl.h:176
Array3DImpl::get3DData
const T *** get3DData() const
Definition: arrayndimpl.h:177
Array2D::info
virtual const Array2DInfo & info() const =0
ArrayImplBase
Definition: arrayndimpl.h:24
Array3DImpl::ptr3d_
T *** ptr3d_
Definition: arrayndimpl.h:189
Array4DImpl::eraseCache
void eraseCache()
Definition: arrayndimpl.h:879
Array1DImpl::setSize
bool setSize(int64_t sz)
Definition: arrayndimpl.h:79
Array1DImpl::Array1DImpl
Array1DImpl(const Array1DImpl< T > &)
Definition: arrayndimpl.h:400
ArrayND::getND
virtual T getND(const int *) const =0
ArrayNDImpl::canSetStorage
bool canSetStorage() const
Definition: arrayndimpl.h:267
ArrayNDImpl::canSetInfo
bool canSetInfo() const
Definition: arrayndimpl.h:275
Array2DImpl::in_
Array2DInfoImpl in_
Definition: arrayndimpl.h:140
ArrayImplBase::storageOK
bool storageOK() const
Definition: arrayndimpl.h:350
Array1DImpl::Array1DImpl
Array1DImpl(const Array1D< T > &)
Definition: arrayndimpl.h:391
ArrayND::setInfo
virtual bool setInfo(const ArrayNDInfo &)
Definition: arraynd.h:67
Array2DImpl::getStorageSize
int64_t getStorageSize() const
Definition: arrayndimpl.h:136
Array2DImpl::Array2DImpl
Array2DImpl(const Array2DInfo &)
Definition: arrayndimpl.h:468
Array4DImpl::canSetInfo
bool canSetInfo() const
Definition: arrayndimpl.h:219
Array2DImpl
Implementation of Array2D.
Definition: arrayndimpl.h:102
Array2DInfoImpl
Implementation of Array2DInfo.
Definition: arrayndinfo.h:212
Array3DImpl::setInfo
bool setInfo(const ArrayNDInfo &)
Definition: arrayndimpl.h:692
Array4DImpl::cachestor_
TypeSet< T *** > cachestor_
Definition: arrayndimpl.h:236
ArrayNDImpl::getStorage_
const ValueSeries< T > * getStorage_() const
Definition: arrayndimpl.h:285
OD::DataRepType
DataRepType
Definition: commontypes.h:49
ArrayNDImpl::getStorageSize
int64_t getStorageSize() const
Definition: arrayndimpl.h:286
Array1DImpl::arr
const T * arr() const
Definition: arrayndimpl.h:84
Array3DImpl::Array3DImpl
Array3DImpl(const Array3D< T > &)
Definition: arrayndimpl.h:620
ArrayNDInfo::clone
virtual ArrayNDInfo * clone() const =0
Array2DImpl::set
void set(int, int, T)
Definition: arrayndimpl.h:497
ArrayND
An ArrayND is an array with a given number of dimensions and a size.
Definition: arraynd.h:33
Array2DImpl::copyFrom
void copyFrom(const Array2D< T > &)
Definition: arrayndimpl.h:547
Array4DImpl::~Array4DImpl
~Array4DImpl()
Definition: arrayndimpl.h:204
Array1DInfoImpl
Implementation of Array1DInfo.
Definition: arrayndinfo.h:186
Array4DImpl::get4DData
const T **** get4DData() const
Definition: arrayndimpl.h:224
Array3DImpl::base
ArrayImplBase< T > base
Definition: arrayndimpl.h:151
Array1DImpl::setInfo
bool setInfo(const ArrayNDInfo &)
Definition: arrayndimpl.h:442
ArrayNDInfo::getNDim
virtual int getNDim() const =0
Array1DImpl::canSetInfo
bool canSetInfo() const
Definition: arrayndimpl.h:76
Array2DImpl::setSize
bool setSize(int, int)
Definition: arrayndimpl.h:565
ArrayND::getAll
virtual void getAll(T *ptr) const
Definition: arraynd.h:547
Array3DImpl::setStorage
bool setStorage(ValueSeries< T > *vs)
Definition: arrayndimpl.h:684
ArrayImplBase::setStorageInternal
bool setStorageInternal(ValueSeries< T > *)
Definition: arrayndimpl.h:314
Array1DImpl::clone
ValueSeries< T > * clone() const
Definition: arrayndimpl.h:63
ArrayNDImpl::base
ArrayImplBase< T > base
Definition: arrayndimpl.h:250
Array1DImpl::get
T get(int pos) const
Definition: arrayndimpl.h:421
create
static uiHor3DInterpol * create(uiParent *)
Array4DImpl::get4DData
T **** get4DData()
Definition: arrayndimpl.h:223
Array4DImpl::inf_
Array4DInfoImpl inf_
Definition: arrayndimpl.h:238
Array4DImpl::base
ArrayImplBase< T > base
Definition: arrayndimpl.h:198
Array1DImpl::copyFrom
void copyFrom(const Array1D< T > &)
Definition: arrayndimpl.h:432
DBG::forceCrash
void forceCrash(bool withdump)
Array2DImpl::getStorage_
const ValueSeries< T > * getStorage_() const
Definition: arrayndimpl.h:135
ArrayNDImpl::setStorage
bool setStorage(ValueSeries< T > *vs)
Definition: arrayndimpl.h:268
Array1DImpl::getStorage_
const ValueSeries< T > * getStorage_() const
Definition: arrayndimpl.h:88
Array3DImpl::getStorage_
const ValueSeries< T > * getStorage_() const
Definition: arrayndimpl.h:182
Array2DImpl::get
T get(int, int) const
Definition: arrayndimpl.h:519
Array3DImpl::getData_
const T * getData_() const
Definition: arrayndimpl.h:181
ArrayImplBase::ptr_
T * ptr_
Definition: arrayndimpl.h:41
Array1DImpl::getStorageSize
int64_t getStorageSize() const
Definition: arrayndimpl.h:89
ArrayNDImpl::~ArrayNDImpl
~ArrayNDImpl()
Definition: arrayndimpl.h:959
ArrayNDImpl::copyFrom
void copyFrom(const ArrayND< T > &)
Definition: arrayndimpl.h:964
Array1DImpl::setStorage
bool setStorage(ValueSeries< T > *vs)
Definition: arrayndimpl.h:68
Array2D
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:140
ArrayND::getData
const T * getData() const
Definition: arraynd.h:54
Array2DImpl::~Array2DImpl
~Array2DImpl()
Definition: arrayndimpl.h:108
ArrayNDImpl::clone
static bool clone(const ArrayND< T > &, ArrayND< T > &)
Definition: arrayndimpl.h:1064
Array4DInfoImpl
Implementation of Array4DInfo.
Definition: arrayndinfo.h:263
debug.h
Array2DImpl::Array2DImpl
Array2DImpl(const Array2DImpl< T > &)
Definition: arrayndimpl.h:487
ValueSeries::arr
virtual T * arr()
Definition: valseries.h:55
ArrayNDImpl::in_
ArrayNDInfo * in_
Definition: arrayndimpl.h:288
Array1DImpl::in_
Array1DInfoImpl in_
Definition: arrayndimpl.h:91
TypeSet< T ** >
Array3DImpl::getStorageSize
int64_t getStorageSize() const
Definition: arrayndimpl.h:183
Array4DImpl::updateStorage
void updateStorage()
Definition: arrayndimpl.h:871
Array3DImpl::~Array3DImpl
~Array3DImpl()
Definition: arrayndimpl.h:157

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021