SMIL  0.9.1
DStructuringElement.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _STR_ELT_HPP
31 #define _STR_ELT_HPP
32 
33 #include "Core/include/DCommon.h"
34 #include "Core/include/DBaseObject.h"
35 
36 
37 namespace smil
38 {
45  enum seType { SE_Generic, SE_Hex, SE_Squ, SE_Cross, SE_Horiz, SE_Vert, SE_Cube, SE_Cross3D, SE_Rhombicuboctahedron };
46 
47 
51  class StrElt : public BaseObject
52  {
53  public:
54  StrElt(UINT s=1)
55  : BaseObject("StrElt"),
56  odd(false),
57  seT(SE_Generic),
58  size(s)
59  {
60  }
61 
62  StrElt(const StrElt &rhs)
63  : BaseObject(rhs)
64  {
65  this->clone(rhs);
66  }
67 
68 #ifndef SWIG
69  StrElt(bool oddSE, UINT nbrPts, ...)
70  : BaseObject("StrElt"),
71  odd(oddSE),
72  seT(SE_Generic),
73  size(1)
74  {
75  UINT index;
76  va_list vl;
77  va_start(vl, nbrPts);
78 
79  for (UINT i=0;i<nbrPts;i++)
80  {
81  index = va_arg(vl, UINT);
82  addPoint(index);
83  }
84  }
85 #endif // SWIG
86 
104  StrElt(bool oddSE, vector<UINT> indexList)
105  : BaseObject("StrElt"),
106  odd(oddSE),
107  seT(SE_Generic),
108  size(1)
109  {
110  for (vector<UINT>::iterator it=indexList.begin();it!=indexList.end();it++)
111  addPoint(*it);
112  }
113 
114  ~StrElt() {}
115 
116  IntPoint getPoint (const UINT i) {
117  return points[i];
118  }
119  UINT getSize() const {return size;}
120 
121  StrElt& operator=(const StrElt &rhs);
122  void clone(const StrElt &rhs);
123 
125  vector<IntPoint> points;
126 
127  void addPoint(const UINT index);
128  void addPoint(int x, int y, int z=0);
129  void addPoint(const IntPoint &pt);
130  const StrElt operator()(int s=1) const;
131 
133  StrElt homothety(const UINT s) const;
134 
136  StrElt transpose() const;
137 
139  StrElt noCenter () const;
140 
141  bool odd;
142  seType seT;
143  UINT size;
144  virtual seType getType() const { return seT; }
145 
146  virtual void printSelf(ostream &os = std::cout, string indent="") const;
147  };
148 
149  inline void operator << (ostream &os, StrElt &se)
150  {
151  se.printSelf(os);
152  }
153 
161  class SquSE : public StrElt
162  {
163  public:
164  SquSE(UINT s=1)
165  : StrElt(false, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8)
166  {
167  className = "SquSE";
168  seT = SE_Squ;
169  size = s;
170  }
171  };
172 
181  class SquSE0 : public StrElt
182  {
183  public:
184  typedef StrElt parentClass;
185  SquSE0(UINT s=1)
186  : StrElt(false, 8, 1, 2, 3, 4, 5, 6, 7, 8)
187  {
188  className = "SquSE0";
189  odd = false;
190  size = s;
191  }
192  };
193 
201  class HexSE : public StrElt
202  {
203  public:
204  HexSE(UINT s=1)
205  : StrElt(true, 7, 0, 1, 2, 3, 4, 5, 6)
206  {
207  className = "HexSE";
208  seT = SE_Hex;
209  size = s;
210  }
211  };
212 
221  class HexSE0 : public StrElt
222  {
223  public:
224  HexSE0(UINT s=1)
225  : StrElt(true, 6, 1, 2, 3, 4, 5, 6)
226  {
227  className = "HexSE0";
228  size = s;
229  }
230  };
231 
232 
233 
242  class CrossSE : public StrElt
243  {
244  public:
245  CrossSE(UINT s=1)
246  : StrElt(false, 5, 0, 1, 5, 3, 7)
247  {
248  className = "CrossSE";
249  seT = SE_Cross;
250  size = s;
251  }
252  };
253 
262  class HorizSE : public StrElt
263  {
264  public:
265  HorizSE(UINT s=1)
266  : StrElt(false, 3, 0, 1, 5)
267  {
268  className = "HorizSE";
269  seT = SE_Horiz;
270  size = s;
271  }
272  };
273 
282  class VertSE : public StrElt
283  {
284  public:
285  VertSE(UINT s=1)
286  : StrElt(false, 3, 0, 3, 7)
287  {
288  className = "VertSE";
289  seT = SE_Vert;
290  size = s;
291  }
292  };
293 
294 
302  class CubeSE : public StrElt
303  {
304  public:
305  CubeSE(UINT s=1) : StrElt(s)
306  {
307  this->className = "CubeSE";
308  this->seT = SE_Cube;
309  odd = false;
310  int zList[] = { 0, -1, 1 };
311  for (int i=0;i<3;i++)
312  {
313  int z = zList[i];
314  addPoint(0,0,z);
315  addPoint(1,0,z);
316  addPoint(1,-1,z);
317  addPoint(0,-1,z);
318  addPoint(-1,-1,z);
319  addPoint(-1,0,z);
320  addPoint(-1,1,z);
321  addPoint(0,1,z);
322  addPoint(1,1,z);
323  }
324  }
325  };
326 
334  class Cross3DSE : public StrElt
335  {
336  public:
337  Cross3DSE(UINT s=1)
338  : StrElt(s)
339  {
340  className = "Cross3DSE";
341  seT = SE_Cross3D;
342  odd = false;
343  addPoint(0,0,0);
344  addPoint(1,0,0);
345  addPoint(0,-1,0);
346  addPoint(-1,0,0);
347  addPoint(0,1,0);
348  addPoint(0,0,-1);
349  addPoint(0,0,1);
350  }
351  };
352 
358  {
359  public:
360  RhombicuboctahedronSE(UINT s=1)
361  : StrElt(s)
362  {
363  className = "RhombicuboctahedronSE";
364  seT = SE_Rhombicuboctahedron;
365  odd = false;
366 
367  int x, y, z;
368 
369  addPoint(0,0,0);
370  for (x = -2; x <= 2; x++)
371  for (y = -1; y <= 1; y++)
372  for (z = -1; z <= 1; z++)
373  addPoint(x, y, z);
374  for (x = -1; x <= 1; x++)
375  for (y = -2; y <= 2; y++)
376  for (z = -1; z <= 1; z++)
377  addPoint(x, y, z);
378  for (x = -1; x <= 1; x++)
379  for (y = -1; y <= 1; y++)
380  for (z = -2; z <= 2; z++)
381  addPoint(x, y, z);
382  }
383  };
384 
385  // Shortcuts
386  inline HexSE hSE(UINT s=1) { return HexSE(s); }
387  inline HexSE0 hSE0(UINT s=1) { return HexSE0(s); }
388  inline SquSE sSE(UINT s=1) { return SquSE(s); }
389  inline SquSE0 sSE0(UINT s=1) { return SquSE0(s); }
390  inline CrossSE cSE(UINT s=1) { return CrossSE(s); }
391  inline CubeSE cbSE(UINT s=1) { return CubeSE(s); }
392  inline RhombicuboctahedronSE rcoSE(UINT s=1) { return RhombicuboctahedronSE(s); }
393 
394 
395  #define DEFAULT_SE Morpho::getDefaultSE()
396 
399 } // namespace smil
400 
401 
402 
403 #endif
Square structuring element.
Definition: DStructuringElement.h:161
Definition: DColorConvert.h:38
vector< IntPoint > points
List of neighbor points.
Definition: DStructuringElement.h:125
Square structuring element without center point.
Definition: DStructuringElement.h:181
StrElt homothety(const UINT s) const
Construct and return an homothetic SE with size s.
Definition: DStructuringElement.cpp:78
StrElt(bool oddSE, vector< UINT > indexList)
Construct a structuring element with points defined by their indexes.
Definition: DStructuringElement.h:104
Rhombicuboctahedron struturing element (80 neighbors).
Definition: DStructuringElement.h:357
Vertical segment structuring element.
Definition: DStructuringElement.h:282
Base Smil Object.
Definition: DBaseObject.h:53
StrElt transpose() const
Return the opposite SE (symmetry with respect to 0)
Definition: DStructuringElement.cpp:110
Base structuring element.
Definition: DStructuringElement.h:51
3D Cubic structuring element (26 neighbors).
Definition: DStructuringElement.h:302
StrElt noCenter() const
Return the SE with no center.
Definition: DStructuringElement.cpp:127
Cross structuring element.
Definition: DStructuringElement.h:242
Hexagonal structuring element without center point.
Definition: DStructuringElement.h:221
Hexagonal structuring element.
Definition: DStructuringElement.h:201
Horizontal segment structuring element.
Definition: DStructuringElement.h:262
Definition: DCommon.h:104
3D Cross structuring element (6 neighbors).
Definition: DStructuringElement.h:334