/usr/include/gamera/plugins/logical.hpp is in python-gamera-dev 3.4.2+svn1437-2.
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 | /*
*
* Copyright (C) 2001-2005 Ichiro Fujinaga, Michael Droettboom, and Karl MacMillan
*
* This program 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 2
* 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef kwm10092002_logical
#define kwm10092002_logical
#include "gamera.hpp"
#include <functional>
#include <exception>
namespace Gamera {
template<class T, class U, class FUNCTOR>
inline typename ImageFactory<T>::view_type*
logical_combine(T& a, const U& b, const FUNCTOR& functor, bool in_place) {
if (a.nrows() != b.nrows() || a.ncols() != b.ncols())
throw std::runtime_error("Images must be the same size.");
//typedef typename T::value_type TVALUE;
typedef typename ImageFactory<T>::view_type VIEW;
if (in_place) {
typename T::vec_iterator ia = a.vec_begin();
typename U::const_vec_iterator ib = b.vec_begin();
typename choose_accessor<T>::accessor ad = choose_accessor<T>::make_accessor(a);
for (; ia != a.vec_end(); ++ia, ++ib) {
bool b = functor(is_black(*ia), is_black(*ib));
if (b)
ad.set(white(a), ia);
else
ad.set(black(a), ia);
}
// Returning NULL is converted to None by the wrapper mechanism
return NULL;
} else {
typename ImageFactory<T>::data_type* dest_data =
new typename ImageFactory<T>::data_type(a.size(), a.origin());
VIEW* dest = new VIEW(*dest_data);
typename T::vec_iterator ia = a.vec_begin();
typename U::const_vec_iterator ib = b.vec_begin();
typename VIEW::vec_iterator id = dest->vec_begin();
typename choose_accessor<VIEW>::accessor ad = choose_accessor<VIEW>::make_accessor(*dest);
try {
// Vigra's combineTwoImages does not clip back to one of the standard
// Gamera image types, so we have to do this differently ourselves. MGD
for (; ia != a.vec_end(); ++ia, ++ib, ++id) {
bool b = functor(is_black(*ia), is_black(*ib));
if (b)
ad.set(white(a), id);
else
ad.set(black(a), id);
}
} catch (std::exception e) {
delete dest;
delete dest_data;
throw;
}
return dest;
}
}
template<class T, class U>
typename ImageFactory<T>::view_type*
and_image(T& a, const U& b, bool in_place=true) {
//typedef typename T::value_type value_type;
return logical_combine(a, b, std::logical_and<bool>(), in_place);
}
template<class T, class U>
typename ImageFactory<T>::view_type*
or_image(T& a, const U& b, bool in_place=true) {
//typedef typename T::value_type value_type;
return logical_combine(a, b, std::logical_or<bool>(), in_place);
};
// We make our own, since logical_xor is not in STL
template <class _Tp>
struct logical_xor : public std::binary_function<_Tp,_Tp,bool>
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x ^ __y; }
};
template<class T, class U>
typename ImageFactory<T>::view_type*
xor_image(T& a, const U& b, bool in_place=true) {
//typedef typename T::value_type value_type;
return logical_combine(a, b, logical_xor<bool>(), in_place);
}
}
#endif
|