1 #ifndef LOCARNA_MATRICES_HH
2 #define LOCARNA_MATRICES_HH
36 template <
class elem_t>
58 addr(size_type i, size_type j)
const {
59 assert(
xl_ <= i && i <=
xr_);
60 assert(
yl_ <= j && j <=
yr_);
82 resize(size_type xdim, size_type ydim) {
85 this->
mat_.resize(xdim * ydim);
99 restrict(size_type xl, size_type xr, size_type yl, size_type yr) {
102 assert(xr < this->
xdim_);
103 assert(yr < this->
ydim_);
112 this->xfactor_ = (yr - yl) + 1;
114 this->offset_ =
addr(xl, yl);
155 get(size_type i, size_type j)
const {
180 for (size_type i =
xl_; i <
xr_; ++i)
181 for (size_type j =
yl_; j <
yr_; ++j)
182 this->
mat_(i, j) = val;
188 template <
class elem_t>
207 addr(
size_t i,
size_t j)
const {
208 assert(
xoff_ <= i && i < xoff_ + this->
xdim_);
209 assert(
yoff_ <= j && j < yoff_ + this->
ydim_);
210 return i * this->ydim_ + j -
off_;
230 resize(
size_t xdim,
size_t ydim,
size_t xoff = 0,
size_t yoff = 0) {
233 off_ = xoff * ydim + yoff;
236 this->
mat_.resize(xdim * ydim);
277 get(
size_t i,
size_t j)
const {
298 template <
class elem_t>
314 rot(
size_t x,
size_t r,
size_t d) {
316 return (x + d - r) % d;
331 addr(
size_t i,
size_t j)
const {
332 assert(
xrot_ <= i && i < xrot_ + this->
xdim_);
333 assert(
yrot_ <= j && j < yrot_ + this->
ydim_);
334 return rot(i,
xrot_, this->xdim_) * this->xdim_ +
355 resize(
size_t xdim,
size_t ydim,
size_t xrot = 0,
size_t yrot = 0) {
360 this->
mat_.resize(xdim * ydim);
371 move(
size_t xrot,
size_t yrot) {
414 get(
size_t i,
size_t j)
const {
simple 2D matrix class, provides access via operator (int,int)
Definition: matrix.hh:31
elem_t elem_t
type of elements
Definition: matrix.hh:33
size_type ydim_
second dimension
Definition: matrix.hh:43
std::vector< elem_t > mat_
vector storing the matrix entries
Definition: matrix.hh:41
size_type xdim_
first dimension
Definition: matrix.hh:42
Simple matrix class with offset.
Definition: matrices.hh:189
size_t addr(size_t i, size_t j) const
Computes address/index in 1D vector from 2D matrix indices.
Definition: matrices.hh:207
size_t yoff_
offset in second dimension
Definition: matrices.hh:193
void set(size_t i, size_t j, const elem_t &x)
Definition: matrices.hh:290
OMatrix()
Definition: matrices.hh:219
elem_t & operator()(size_t i, size_t j)
Definition: matrices.hh:263
void resize(size_t xdim, size_t ydim, size_t xoff=0, size_t yoff=0)
Definition: matrices.hh:230
const elem_t & operator()(size_t i, size_t j) const
Definition: matrices.hh:249
size_t xoff_
offset in first dimension
Definition: matrices.hh:192
const elem_t get(size_t i, size_t j) const
Definition: matrices.hh:277
size_t off_
combined offset for vector access
Definition: matrices.hh:191
Simple matrix class with restriction to a range.
Definition: matrices.hh:37
size_type offset_
offset for index calculation
Definition: matrices.hh:46
elem_t & operator()(size_type i, size_type j)
Definition: matrices.hh:141
size_type yl_
left end of restriction in second dimension
Definition: matrices.hh:42
void resize(size_type xdim, size_type ydim)
Definition: matrices.hh:82
void fill(const elem_t &val)
Fill the whole matrix with the given value.
Definition: matrices.hh:179
size_type xr_
right end of restriction in first dimension
Definition: matrices.hh:41
size_type xfactor_
factor for index calculation
Definition: matrices.hh:45
const elem_t get(size_type i, size_type j) const
Definition: matrices.hh:155
void restrict(size_type xl, size_type xr, size_type yl, size_type yr)
Set new restricted range.
Definition: matrices.hh:99
size_type xl_
left end of restriction in first dimension
Definition: matrices.hh:40
size_type addr(size_type i, size_type j) const
Definition: matrices.hh:58
RMatrix()
Definition: matrices.hh:70
void set(size_type i, size_type j, const elem_t &x)
Definition: matrices.hh:168
size_type yr_
right end of restriction in second dimension
Definition: matrices.hh:43
const elem_t & operator()(size_type i, size_type j) const
Definition: matrices.hh:127
A matrix class with rotation.
Definition: matrices.hh:299
void move(size_t xrot, size_t yrot)
Definition: matrices.hh:371
const elem_t & operator()(size_t i, size_t j) const
Definition: matrices.hh:386
RotMatrix()
Definition: matrices.hh:344
elem_t & operator()(size_t i, size_t j)
Definition: matrices.hh:400
size_t rot(size_t x, size_t r, size_t d)
Definition: matrices.hh:314
void resize(size_t xdim, size_t ydim, size_t xrot=0, size_t yrot=0)
Definition: matrices.hh:355
const elem_t get(size_t i, size_t j) const
Definition: matrices.hh:414
size_t xrot_
rotation in dimension 1
Definition: matrices.hh:301
size_t yrot_
rotation in dimension 2
Definition: matrices.hh:302
size_t addr(size_t i, size_t j) const
Definition: matrices.hh:331
void set(size_t i, size_t j, const elem_t &x)
Definition: matrices.hh:428
Definition: aligner.cc:15