/usr/include/mia-2.2/mia/2d/datafield.cxx is in libmia-2.2-dev 2.2.7-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | /* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2015 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#undef mia_2d_datafield_cxx
#ifndef mia_2d_datafield_cxx
#define mia_2d_datafield_cxx
#include <stdexcept>
#include <mia/2d/datafield.hh>
#include <mia/core/msgstream.hh>
NS_MIA_BEGIN
template <class T>
T2DDatafield<T>::T2DDatafield(const C2DBounds& _Size):
m_size(_Size),
m_data(new data_array(m_size.x * m_size.y))
{
}
template <class T>
T2DDatafield<T>::T2DDatafield():
m_size(C2DBounds(0,0)),
m_data(new data_array(0))
{
}
template <class T>
T2DDatafield<T>::T2DDatafield(const C2DBounds& size,const T *_data):
m_size(size),
m_data(new data_array(m_size.x * m_size.y))
{
if (_data)
::std::copy(_data, _data + m_data->size(), m_data->begin());
else
::std::fill(m_data->begin(), m_data->end(), T());
}
template <class T>
T2DDatafield<T>::T2DDatafield(const C2DBounds& size, const data_array& data):
m_size(size),
m_data(new data_array(data))
{
assert(m_data->size() == m_size.x * m_size.y);
}
template <class T>
T2DDatafield<T>::T2DDatafield(const T2DDatafield<T>& org):
m_size(org.m_size),
m_data(org.m_data)
{
}
template <class T>
T2DDatafield<T>::~T2DDatafield()
{
}
template <class T>
void T2DDatafield<T>::make_single_ref()
{
if (!m_data.unique())
m_data = data_pointer(new data_array(*m_data));
}
template <class T>
typename T2DDatafield<T>::size_type T2DDatafield<T>::size() const
{
return m_data->size();
}
template <class T>
T T2DDatafield<T>::get_interpol_val_at(const C2DFVector& p) const
{
size_t x = (size_t )p.x;
size_t y = (size_t )p.y;
float xp = p.x - x; float xm = 1.0 - xp;
float yp = p.y - y; float ym = 1.0 - yp;
const T& H00 = (*this)(x ,y );
const T& H01 = (*this)(x ,y+1);
const T& H10 = (*this)(x+1,y );
const T& H11 = (*this)(x+1,y+1);
return T(ym * ( xm * H00 + xp * H10) +
yp * ( xm * H01 + xp * H11));
}
template <class T>
const C2DBounds& T2DDatafield<T>::get_size() const
{
return m_size;
}
template <class T>
void T2DDatafield<T>::clear()
{
make_single_ref();
std::fill(begin(), end(),T());
}
template <class T>
typename T2DDatafield<T>::reference
T2DDatafield<T>::operator()(size_t x, size_t y)
{
if (x < m_size.x && y < m_size.y){
return (*m_data)[x + m_size.x * y ];
}else{
//FORCECOREDUMP;
throw std::invalid_argument("T2DDatafield<T>::operator(x,y,z):Index out of bounds");
}
}
template <class T>
typename T2DDatafield<T>::const_reference
T2DDatafield<T>::operator()(size_t x, size_t y)const
{
const data_array& cData = *m_data;
if ( x < m_size.x && y < m_size.y ){
return cData[ x + m_size.x * y ];
}else{
return Zero;
}
}
template <class T>
typename T2DDatafield<T>::const_reference
T2DDatafield<T>::operator()(const C2DBounds& l)const
{
const data_array& cData = *m_data;
if ( l.x < m_size.x && l.y < m_size.y ){
return cData[ l.x + m_size.x * l.y ];
}else{
return Zero;
}
}
template <class T>
typename T2DDatafield<T>::reference
T2DDatafield<T>::operator()(const C2DBounds& l)
{
return (*this)(l.x,l.y);
}
template <class T>
void T2DDatafield<T>::get_data_line_x(size_t y, std::vector<T>& buffer)const
{
assert(y < m_size.y);
buffer.resize(m_size.x);
const data_array& d = *m_data;
const_iterator b = d.begin();
advance(b, y * m_size.x);
std::copy(b, b + m_size.x, buffer.begin());
}
template <class T>
void T2DDatafield<T>::get_data_line_y(size_t x, std::vector<T>& buffer)const
{
assert(x < m_size.x);
buffer.resize(m_size.y);
const data_array& d = *m_data;
const_iterator src = d.begin();
advance(src,x);
typename std::vector<T>::iterator dest_i = buffer.begin();
typename std::vector<T>::iterator dest_e = buffer.end();
size_t idx = 0;
while (dest_i != dest_e) {
*dest_i = src[idx];
idx += m_size.x;
++dest_i;
}
}
template <class T>
void T2DDatafield<T>::put_data_line_x(size_t y, const std::vector<T>& buffer)
{
assert(y < m_size.y);
assert(buffer.size() == m_size.x);
make_single_ref();
std::copy(buffer.begin(), buffer.end(), m_data->begin() + m_size.x * y );
}
template <class T>
void T2DDatafield<T>::put_data_line_y(size_t x, const std::vector<T>& buffer)
{
assert(x < m_size.x);
assert(buffer.size() == m_size.y);
make_single_ref();
typename std::vector<T>::const_iterator src_i = buffer.begin();
typename std::vector<T>::const_iterator src_e = buffer.end();
iterator dest = begin();
advance(dest, x);
size_t idx = 0;
while ( src_i != src_e ) {
dest[idx] = *src_i;
idx += m_size.x;
++src_i;
}
}
template <class T>
T2DDatafield<T>& T2DDatafield<T>::operator = (const T2DDatafield<T>& org)
{
if (&org == this){
return *this;
}
m_size = org.m_size;
m_data = org.m_data;
return *this;
}
template <typename T>
typename T2DDatafield<T>::range_iterator
T2DDatafield<T>::begin_range(const C2DBounds& begin, const C2DBounds& end)
{
return range_iterator(begin, get_size(), begin, end,
begin_at(begin.x, begin.y));
}
template <typename T>
typename T2DDatafield<T>::range_iterator
T2DDatafield<T>::end_range(const C2DBounds& begin, const C2DBounds& end)
{
return range_iterator(end, get_size(), begin, end,
begin_at(end.x, end.y));
}
template <typename T>
typename T2DDatafield<T>::const_range_iterator
T2DDatafield<T>::begin_range(const C2DBounds& begin, const C2DBounds& end)const
{
return const_range_iterator(begin, get_size(), begin, end,
begin_at(begin.x, begin.y));
}
template <typename T>
typename T2DDatafield<T>::const_range_iterator
T2DDatafield<T>::end_range(const C2DBounds& begin, const C2DBounds& end)const
{
return const_range_iterator(end, get_size(), begin, end,
begin_at(end.x, end.y));
}
template <class T>
const T T2DDatafield<T>::Zero = T();
NS_MIA_END
#endif
|