isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Cube.h
1 //-*- C++ -*-
2 //-*- coding: utf-8 -*-
3 //
4 // Author: Piyush Agram
5 // Copyright 2017-2019
6 
7 #pragma once
8 
9 #include "forward.h"
10 
11 #include <cmath>
12 #include <valarray>
13 #include <vector>
14 #include <pyre/grid.h>
15 
16 // isce3::core::Cube definition
17 template <typename cell_t>
19 
20  public:
21  // Types for interfacing with pyre::grid
22  using rep_t = std::array<size_t, 3>;
23  using index_t = pyre::grid::index_t<rep_t>;
24  using layout_t = pyre::grid::layout_t<index_t>;
25 
26  // Use a grid with view memory storage
27  using grid_t = pyre::grid::grid_t<cell_t, layout_t, pyre::memory::view_t<cell_t>>;
28 
29  // Dependent types
30  using view_t = typename grid_t::view_type;
31  using shape_t = typename layout_t::shape_type;
32  using slice_t = typename layout_t::slice_type;
33  using packing_t = typename layout_t::packing_type;
34 
35  public:
37  inline Cube();
38 
40  inline Cube(size_t nslices, size_t nrows, size_t ncols);
41 
43  inline Cube(const Cube<cell_t> & m);
44 
46  inline Cube(Cube<cell_t> & m);
47 
49  inline Cube(cell_t * data, size_t nslices, size_t nrows, size_t ncols);
50 
52  inline Cube(std::valarray<cell_t> & data, size_t nrows, size_t ncols);
53 
55  inline Cube(std::vector<cell_t> & data, size_t nrows, size_t ncols);
56 
58  inline ~Cube();
59 
61  inline Cube<cell_t> & operator=(const Cube<cell_t> & m);
62 
64  inline Cube<cell_t> & operator=(Cube<cell_t> & m);
65 
67  inline void resize(size_t nslices, size_t nrows, size_t ncols);
68 
70  inline const view_t subcube(size_t slice, size_t row, size_t col, size_t slicespan, size_t rowspan, size_t colspan);
71 
73  inline cell_t * data();
74 
76  inline const cell_t * data() const;
77 
79  inline cell_t * sliceptr(size_t slice);
80 
82  inline const cell_t * sliceptr(size_t slice) const;
83 
85  inline cell_t & operator()(size_t slice, size_t row, size_t col);
86 
88  inline const cell_t & operator()(size_t slice, size_t row, size_t col) const;
89 
91  inline cell_t & operator()(size_t index);
92 
94  inline const cell_t & operator()(size_t index) const;
95 
97  inline cell_t & operator[](const index_t & index);
98 
100  inline const cell_t & operator[](const index_t & index) const;
101 
103  inline void zeros();
104 
106  inline void fill(cell_t value);
107 
109  inline shape_t shape() const;
110 
112  inline size_t width() const;
113 
115  inline size_t length() const;
116 
118  inline size_t height() const;
119 
121  inline shape_t byteoffset() const;
122 
123  // Data members
124  private:
125  // Shape information
126  size_t _nslices;
127  size_t _nrows;
128  size_t _ncols;
129 
130  // Dynamic memory data
131  cell_t * _buffer;
132  bool _owner;
133 
134  // grid pointer for slicing support
135  grid_t * _grid;
136 
137  // Utility functions
138  private:
139  // Reset grid pointer
140  inline void _resetGrid();
141 };
142 
143 // Get inline implementations for Cube
144 #define ISCE_CORE_CUBE_ICC
145 #include "Cube.icc"
146 #undef ISCE_CORE_CUBE_ICC
cell_t * data()
Access to data buffer.
Definition: Cube.icc:199
~Cube()
Destructor.
Definition: Cube.icc:102
void resize(size_t nslices, size_t nrows, size_t ncols)
Resize memory for a given number of slices, rows and columns.
Definition: Cube.icc:150
size_t width() const
Get cube width.
Definition: Cube.icc:331
const view_t subcube(size_t slice, size_t row, size_t col, size_t slicespan, size_t rowspan, size_t colspan)
Extract copy of sub-cube given starting indices and span.
Definition: Cube.icc:178
shape_t byteoffset() const
Get byteoffset for row and column for reading flat binary buffer.
Definition: Cube.icc:355
cell_t & operator[](const index_t &index)
Access matrix value for a given grid::index_type.
Definition: Cube.icc:278
cell_t & operator()(size_t slice, size_t row, size_t col)
Access matrix value for a given slice, row and column.
Definition: Cube.icc:240
Cube< cell_t > & operator=(const Cube< cell_t > &m)
Deep assignment operator - allocates memory and copies values.
Definition: Cube.icc:118
cell_t * sliceptr(size_t slice)
Access to data buffer at a specific slice.
Definition: Cube.icc:215
size_t height() const
Get cube height.
Definition: Cube.icc:347
shape_t shape() const
Get shape information as grid::shape_type.
Definition: Cube.icc:323
Cube()
Default constructor.
Definition: Cube.icc:14
void zeros()
Fill with zeros.
Definition: Cube.icc:303
Definition: Cube.h:18
size_t length() const
Get cube length.
Definition: Cube.icc:339
void fill(cell_t value)
Fill with a constant value.
Definition: Cube.icc:313

Generated for ISCE3.0 by doxygen 1.8.5.