[go: up one dir, main page]

Menu

[r991]: / libmona / libmona / shapes.cc  Maximize  Restore  History

Download this file

157 lines (126 with data), 4.1 kB

  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
/* -*- mona-c++ -*-
* Copyright (c) Leipzig, Madrid 2004 - 2008
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string>
#include <libmona/shapes.hh>
#include <libmona/plugin_handler.cxx>
MONA_NAMESPACE_BEGIN
using namespace std;
static char const *plugin_type = "creator";
char const image2d_data[] = "2dshape";
char const image3d_data[] = "3dshape";
template <>
struct less_then< T2DVector<int> > {
bool operator() (const T2DVector<int>& a, const T2DVector<int>& b)const
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
};
template <>
struct less_then< T3DVector<int> > {
bool operator() (const T3DVector<int>& a, const T3DVector<int>& b)const
{
return a.x < b.x || (a.x == b.x && (a.y < b.y || a.y == b.y && a.z < b.z ));
}
};
template <template <typename> class T, typename M>
CShape<T,M>::CShape():
_M_shape(less_then<T<int> >())
{
}
template <template <typename> class T, typename M>
CShape<T,M>::~CShape()
{
}
template <template <typename> class T, typename M>
typename CShape<T,M>::const_iterator CShape<T,M>::begin() const
{
return _M_shape.begin();
}
template <template <typename> class T, typename M>
typename CShape<T,M>::const_iterator CShape<T,M>::end() const
{
return _M_shape.end();
}
static void adjust(T2DVector<int>& size, const T2DVector<int>& p)
{
int x = (p.x < 0 ? -2 * p.x : 2 * p.x) + 1;
int y = (p.y < 0 ? -2 * p.y : 2 * p.y) + 1;
if (size.x < x)
size.x = x;
if (size.y < y)
size.y = y;
}
static void adjust(T3DVector<int>& size, const T3DVector<int>& p)
{
int x = (p.x < 0 ? -2 * p.x : 2 * p.x) + 1;
int y = (p.y < 0 ? -2 * p.y : 2 * p.y) + 1;
int z = (p.z < 0 ? -2 * p.z : 2 * p.z) + 1;
if (size.x < x)
size.x = x;
if (size.y < y)
size.y = y;
if (size.z < z)
size.z = z;
}
template <template <typename> class T, typename M>
typename CShape<T,M>::Size CShape<T,M>::get_size() const
{
return typename CShape<T,M>::Size(_M_size);
}
template <template <typename> class T, typename M>
void CShape<T,M>::insert(const T<int>& p)
{
_M_shape.insert(p);
adjust(_M_size,p);
}
template <template <typename> class T, typename M>
typename CShape<T,M>::Mask CShape<T,M>::get_mask()const
{
typename CShape<T,M>::Mask result(get_size());
result.clear();
T<int> half_size = _M_size / 2;
for (const_iterator i = begin(), e = end(); i != e; ++i){
result(T<unsigned int>(*i + half_size)) = true;
}
return result;
}
template <typename S, const char *P, const char *D>
CShapeFactory<S,P, D>::CShapeFactory(const char *name):
TFactory<S>(name, plugin_type, D)
{
}
template <typename S, const char *P, const char *D>
CShapeFactory<S, P, D>::~CShapeFactory()
{
}
const char plugin_shape_pattern_2d[] = ".*_2dshape_creator\\.so";
const char plugin_shape_pattern_3d[] = ".*_3dshape_creator\\.so";
template class CShape<T2DVector, C2DBitImage>;
template class CShape<T3DVector, C3DBitImage>;
template class CShapeFactory<C2DShape, plugin_shape_pattern_2d, image2d_data>;
template class CShapeFactory<C3DShape, plugin_shape_pattern_3d, image3d_data>;
template class TPluginHandler<C2DShapeFactory>;
template class TPluginHandler<C3DShapeFactory>;
MONA_NAMESPACE_END