File: imageset.cpp

package info (click to toggle)
aoflagger 3.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: cpp: 83,076; python: 10,187; sh: 260; makefile: 178
file content (136 lines) | stat: -rw-r--r-- 3,916 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "aoflagger.h"
#include "structures.h"

#include "../structures/image2d.h"

#include <stdexcept>

namespace aoflagger {

ImageSet::ImageSet() : _data(nullptr) {}

ImageSet::ImageSet(size_t width, size_t height, size_t count)
    : _data(new ImageSetData(count)) {
  assertValidCount(count);
  for (size_t i = 0; i != count; ++i)
    _data->images[i] = Image2D::CreateUnsetImagePtr(width, height);
}

ImageSet::ImageSet(size_t width, size_t height, size_t count,
                   float initialValue)
    : _data(new ImageSetData(count)) {
  assertValidCount(count);
  for (size_t i = 0; i != count; ++i)
    _data->images[i] = Image2D::CreateSetImagePtr(width, height, initialValue);
}

ImageSet::ImageSet(size_t width, size_t height, size_t count,
                   size_t widthCapacity)
    : _data(new ImageSetData(count)) {
  assertValidCount(count);
  for (size_t i = 0; i != count; ++i)
    _data->images[i] =
        Image2D::CreateUnsetImagePtr(width, height, widthCapacity);
}

ImageSet::ImageSet(size_t width, size_t height, size_t count,
                   float initialValue, size_t widthCapacity)
    : _data(new ImageSetData(count)) {
  assertValidCount(count);
  for (size_t i = 0; i != count; ++i)
    _data->images[i] =
        Image2D::CreateSetImagePtr(width, height, initialValue, widthCapacity);
}

ImageSet::ImageSet(const ImageSet& sourceImageSet)
    : _data(sourceImageSet._data != nullptr
                ? new ImageSetData(*sourceImageSet._data)
                : nullptr) {}

ImageSet::ImageSet::ImageSet(aoflagger::ImageSet&& sourceImageSet)
    : _data(std::move(sourceImageSet._data)) {}

ImageSet::~ImageSet() {}

ImageSet& ImageSet::operator=(const ImageSet& sourceImageSet) {
  if (sourceImageSet._data == nullptr) {
    _data.reset();
  } else if (_data == nullptr) {
    _data.reset(new ImageSetData(*sourceImageSet._data));
  } else {
    *_data = *sourceImageSet._data;
  }
  return *this;
}

ImageSet& ImageSet::operator=(ImageSet&& sourceImageSet) {
  std::swap(_data, sourceImageSet._data);
  return *this;
}

void ImageSet::assertValidCount(size_t count) {
  if (count != 1 && count != 2 && count != 4 && count != 8)
    throw std::runtime_error(
        "Invalid count specified when creating image set for aoflagger; should "
        "be 1, 2, 4 or 8.");
}

float* ImageSet::ImageBuffer(size_t imageIndex) {
  return _data->images[imageIndex]->Data();
}

const float* ImageSet::ImageBuffer(size_t imageIndex) const {
  return _data->images[imageIndex]->Data();
}

size_t ImageSet::Width() const { return _data->images[0]->Width(); }

size_t ImageSet::Height() const { return _data->images[0]->Height(); }

size_t ImageSet::ImageCount() const { return _data->images.size(); }

size_t ImageSet::HorizontalStride() const { return _data->images[0]->Stride(); }

void ImageSet::Set(float newValue) {
  for (const Image2DPtr& image : _data->images) {
    image->SetAll(newValue);
  }
}

void ImageSet::ResizeWithoutReallocation(size_t newWidth) const {
  for (const Image2DPtr& image : _data->images) {
    image->ResizeWithoutReallocation(newWidth);
  }
}

void ImageSet::SetAntennas(size_t antenna1, size_t antenna2) {
  _data->hasAntennas = true;
  _data->antenna1 = antenna1;
  _data->antenna2 = antenna2;
}

bool ImageSet::HasAntennas() const { return _data->hasAntennas; }

size_t ImageSet::Antenna1() const { return _data->antenna1; }

size_t ImageSet::Antenna2() const { return _data->antenna2; }

void ImageSet::SetInterval(size_t index) {
  _data->interval = index;
  _data->hasInterval = true;
}

bool ImageSet::HasInterval() const { return _data->hasInterval; }

size_t ImageSet::Interval() const { return _data->interval; }

void ImageSet::SetBand(size_t index) {
  _data->band = index;
  _data->hasBand = true;
}

bool ImageSet::HasBand() const { return _data->hasBand; }

size_t ImageSet::Band() const { return _data->band; }

}  // namespace aoflagger