Source
43
43
);
44
44
_axis = n;
45
45
}
46
46
47
47
template<class T> SPIIT ImageDecimator<T>::decimate() const {
48
48
ThrowIf(
49
49
_factor > this->_getImage()->shape()[_axis],
50
50
"The value of factor cannot be greater than the "
51
51
"number of pixels along the specified axis"
52
52
);
53
-
casacore::LogOrigin lor = casacore::LogOrigin(getClass(), __func__);
53
+
casacore::LogOrigin lor(getClass(), __func__);
54
54
*this->_getLog() << lor;
55
55
auto subImage = SubImageFactory<T>::createSubImageRO(
56
56
*this->_getImage(), *this->_getRegion(), this->_getMask(), 0,
57
57
casacore::AxesSpecifier(), this->_getStretch()
58
58
);
59
59
if (_factor == 1) {
60
60
*this->_getLog() << casacore::LogIO::WARN << "A decimation factor "
61
61
<< "of 1 has been specified which means no planes will "
62
62
<< "be removed. The resulting image will be a straight "
63
63
<< "copy of the selected image." << casacore::LogIO::POST;
64
64
return this->_prepareOutputImage(*subImage);
65
65
}
66
-
casacore::CoordinateSystem csys = subImage->coordinates();
67
-
casacore::Vector<casacore::Double> refPix = csys.referencePixel();
66
+
auto csys = subImage->coordinates();
67
+
auto refPix = csys.referencePixel();
68
68
refPix[_axis] /= _factor;
69
69
csys.setReferencePixel(refPix);
70
70
casacore::Vector<casacore::Double> inc = csys.increment();
71
71
inc[_axis] *= _factor;
72
72
csys.setIncrement(inc);
73
-
casacore::IPosition subShape = subImage->shape();
74
-
casacore::IPosition shape = subShape;
73
+
auto subShape = subImage->shape();
74
+
auto shape = subShape;
75
75
// integer division
76
76
shape[_axis] = shape[_axis]/_factor;
77
77
if (
78
78
_function == ImageDecimatorData::COPY
79
79
&& subShape[_axis] % _factor != 0
80
80
) {
81
81
shape[_axis]++;
82
82
}
83
83
casacore::TempImage<T> out(shape, csys);
84
-
casacore::IPosition cursorShape = shape;
84
+
auto cursorShape = shape;
85
85
cursorShape[_axis] = _factor;
86
86
casacore::LatticeStepper stepper(subShape, cursorShape);
87
87
casacore::RO_MaskedLatticeIterator<T> inIter(*subImage, stepper);
88
88
inIter.reset();
89
-
casacore::Bool isMasked = subImage->isMasked();
90
-
casacore::uInt ndim = subImage->ndim();
89
+
auto isMasked = subImage->isMasked();
90
+
auto ndim = subImage->ndim();
91
91
casacore::IPosition begin(ndim, 0);
92
-
casacore::IPosition end = cursorShape - 1;
93
-
std::shared_ptr<casacore::ArrayLattice<casacore::Bool> > outMask(
94
-
isMasked ? new casacore::ArrayLattice<casacore::Bool>(out.shape()) : 0
92
+
auto end = cursorShape - 1;
93
+
std::shared_ptr<casacore::ArrayLattice<casacore::Bool>> outMask(
94
+
isMasked ? new casacore::ArrayLattice<casacore::Bool>(out.shape()) : nullptr
95
95
);
96
-
casacore::IPosition outPos = begin;
96
+
auto outPos = begin;
97
97
if (_function == ImageDecimatorData::COPY) {
98
98
end[_axis] = 0;
99
99
while(! inIter.atEnd() && outPos[_axis]<shape[_axis]) {
100
100
if (isMasked) {
101
101
const casacore::Array<casacore::Bool> mask = inIter.getMask();
102
102
casacore::Array<casacore::Bool> maskSlice = mask(begin, end);
103
103
outMask->putSlice(maskSlice, outPos);
104
104
}
105
105
const casacore::Array<T> data = inIter.cursor();
106
106
casacore::Array<T> dataSlice = data(begin, end);
109
109
outPos[_axis]++;
110
110
}
111
111
}
112
112
else if (_function == ImageDecimatorData::MEAN) {
113
113
casacore::String comment;
114
114
ImageCollapser<T> collapser(
115
115
subImage, casacore::IPosition(1, _axis), false,
116
116
ImageCollapserData::MEAN, "", false
117
117
);
118
118
std::unique_ptr<casacore::Record> reg;
119
-
120
119
casacore::Vector<casacore::Double> start(ndim);
121
120
casacore::Vector<casacore::Int> lattShape(ndim);
122
121
casacore::Vector<casacore::Double> stop(ndim);
123
122
for (casacore::uInt i=0; i<ndim; i++) {
124
123
start[i] = begin[i];
125
124
stop[i] = begin[i] + cursorShape[i] - 1;
126
125
lattShape[i] = subShape[i];
127
126
}
128
127
SPIIT collapsed;
129
-
while(! inIter.atEnd() && outPos[_axis]<shape[_axis]) {
128
+
while(! inIter.atEnd() && (outPos[_axis] < shape[_axis])) {
130
129
reg.reset(
131
130
casacore::RegionManager::box(
132
-
start, stop,
133
-
lattShape, comment
131
+
start, stop, lattShape, comment
134
132
)
135
133
);
136
134
collapser.setRegion(*reg);
137
135
collapsed = collapser.collapse();
138
136
if (isMasked) {
139
137
if (collapsed->isMasked()) {
140
138
casacore::Array<casacore::Bool> mask = collapsed->pixelMask().get();
141
139
outMask->putSlice(mask, outPos);
142
140
}
143
141
else {
144
142
casacore::Array<casacore::Bool> mask(collapsed->shape(), true);
145
143
outMask->putSlice(mask, outPos);
146
144
}
147
145
}
148
-
const casacore::Array<T> data = collapsed->get();
146
+
const auto data = collapsed->get();
149
147
out.putSlice(data, outPos);
150
148
inIter++;
151
149
outPos[_axis]++;
152
150
start[_axis] += _factor;
153
151
stop[_axis] += _factor;
154
152
}
155
153
}
156
154
if (! this->_getSuppressHistory()) {
157
155
ostringstream os;
158
156
os << "Decimated axis " << _axis << " by keeping only every nth plane, "