OpendTect  6.6
arraynddumper.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Bert
8  Date: May 2013
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 
13 -*/
14 
15 #include "algomod.h"
16 #include "arraynd.h"
17 #include "od_iostream.h"
18 
28 template <class T>
30 {
31 public:
32 
33  ArrayNDDumper( const ArrayND<T>& arr )
34  : inp_(arr), haveudfs_(true)
35  , withpos_(false)
36  { setOneLinePerFastestDim(); }
37 
38  inline void setSingleLineWithPos()
39  { withpos_ = true; nlafter_ = 1; }
40  inline void setOneLinePerFastestDim();
41  inline void setOneLinePerSlowestDim();
42 
43  inline void dump(od_ostream&) const;
44 
45  const ArrayND<T>& inp_;
46  bool withpos_;
47  bool haveudfs_;
49 
50 };
51 
52 
53 template <class T>
55 {
56  const int nrdims = inp_.info().getNDim();
57  nlafter_ = nrdims < 2 ? 0 : inp_.info().getSize( nrdims - 1 );
58 }
59 
60 
61 template <class T>
63 {
64  const int nrdims = inp_.info().getNDim();
65  if ( nrdims < 2 )
66  { nlafter_ = 0; return; }
67 
68  nlafter_ = 1;
69  for ( int idim=1; idim<nrdims; idim++ )
70  nlafter_ *= inp_.info().getSize( idim );
71 }
72 
73 
74 template <class T>
76 {
77  if ( inp_.isEmpty() ) return;
78 
79  ArrayNDIter it( inp_.info() );
80  const int nrdims = inp_.info().getNDim();
81 
82  od_int64 nrthisline = 0;
83  while ( true )
84  {
85  const int* pos = it.getPos();
86  if ( withpos_ && nrthisline == 0 )
87  {
88  for ( int idim=0; idim<nrdims; idim++ )
89  strm.add( pos[idim] ).add( od_tab );
90 
91  }
92 
93  const T val = inp_.getND( pos );
94  if ( haveudfs_ && mIsUdf(val) )
95  strm.add( "udf" );
96  else
97  strm.add( val );
98 
99  char wschar = od_tab;
100  if ( nlafter_ > 0 )
101  {
102  nrthisline++;
103  if ( nrthisline == nlafter_ )
104  { wschar = od_newline; nrthisline = 0; }
105  }
106  if ( it.next() )
107  strm.add( wschar );
108  else
109  { strm.add(od_newline).flush(); break; }
110  }
111 }
112 
113 
ArrayNDDumper::dump
void dump(od_ostream &) const
Definition: arraynddumper.h:75
od_ostream::flush
void flush()
od_newline
#define od_newline
Definition: od_iosfwd.h:24
ArrayNDDumper::haveudfs_
bool haveudfs_
Definition: arraynddumper.h:47
mIsUdf
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:289
od_int64
#define od_int64
Definition: plftypes.h:35
ArrayNDDumper::setOneLinePerSlowestDim
void setOneLinePerSlowestDim()
Definition: arraynddumper.h:62
arraynd.h
mClass
#define mClass(module)
Definition: commondefs.h:181
ArrayNDIter::getPos
const int * getPos() const
Definition: arraynd.h:220
ArrayNDDumper::setOneLinePerFastestDim
void setOneLinePerFastestDim()
Definition: arraynddumper.h:54
ArrayNDIter
Iterates through all samples in an ArrayND.
Definition: arraynd.h:209
ArrayNDIter::next
bool next()
ArrayNDDumper::ArrayNDDumper
ArrayNDDumper(const ArrayND< T > &arr)
Definition: arraynddumper.h:33
ArrayNDDumper::withpos_
bool withpos_
Definition: arraynddumper.h:46
ArrayNDDumper::nlafter_
od_int64 nlafter_
Definition: arraynddumper.h:48
od_iostream.h
ArrayNDDumper::inp_
const ArrayND< T > & inp_
Definition: arraynddumper.h:45
ArrayNDDumper::setSingleLineWithPos
void setSingleLineWithPos()
Definition: arraynddumper.h:38
od_ostream::add
od_ostream & add(char)
ArrayND
An ArrayND is an array with a given number of dimensions and a size.
Definition: arraynd.h:33
od_tab
#define od_tab
Definition: od_iosfwd.h:23
ArrayNDDumper
Dumps contents of ArrayND objects.
Definition: arraynddumper.h:30
od_ostream
OD class for stream write common access to the user log file, or std::cout in other than od_main.
Definition: od_ostream.h:26

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