MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WindowScanner.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  WindowScanner.h Search tool which wraps EventWindows
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
27 #ifndef WINDOWSCANNER_H
28 #define WINDOWSCANNER_H
29 
30 #include "Dirs.h"
31 #include "EventWindow.h"
32 
33 namespace MFM
34 {
39  template <class CC>
41  {
42  private:
43  /* Extract short names for parameter types */
44  typedef typename CC::ATOM_TYPE T;
45  typedef typename CC::PARAM_CONFIG P;
46  enum { R = P::EVENT_WINDOW_RADIUS };
47  enum { SITES = EVENT_WINDOW_SITES(R) };
48  enum { W = P::TILE_WIDTH };
49  enum { B = P::ELEMENT_TABLE_BITS };
50 
55  EventWindow<CC>& m_win;
56 
61  Random& m_rand;
62 
63  const u32 EMPTY_TYPE;
64 
65  enum
66  {
67  MOORE_NEIGHBORHOOD_SIZE = 8,
68  VON_NEUMANN_NEIGHBORHOOD_SIZE = 4
69  }NeighborhoodSize;
70 
71  public:
80 
85  { }
86 
106  bool FillIfType(const SPoint& relative, const u32 type, const T& atom);
107 
128  bool FillIfNotType(const SPoint& relative, const u32 type, const T& atom);
129 
145  bool FillIfEmpty(const SPoint& relative, const T& atom);
146 
163  bool CanSeeAtomOfType(const u32 type, const u32 radius) const;
164 
181  u32 CountAtomsOfType(const u32 type, const u32 radius) const;
182 
197  u32 CountEmptyAtoms(const u32 radius) const;
198 
219  bool IsBorderingNeighborhood(const u32 type,
220  const Dir* neighborhood,
221  const u32 dirCount) const;
222 
234  bool IsBorderingMoore(const u32 type) const;
235 
246  bool IsBorderingVonNeumann(const u32 type) const;
247 
248 
265  u32 CountInNeighborhood(const u32 type,
266  const Dir* neighborhood,
267  const u32 dirCount) const;
268 
279  u32 CountMooreNeighbors(const u32 type) const;
280 
291  u32 CountVonNeumannNeighbors(const u32 type) const;
292 
310  u32 FindRandomLocationOfType(const u32 type, SPoint& outPoint) const;
311 
335  u32 FindRandomLocationOfType(const u32 type, const u32 radius, SPoint& outPoint) const;
336 
357  u32 FindRandomInSubWindow(const u32 type, const SPoint* subWindow,
358  const u32 subCount, SPoint& outPoint) const;
359 
378  u32 FindEmptyInSubWindow(const SPoint* subWindow,
379  const u32 subCount, SPoint& outPoint) const;
380 
402  u32 FindRandomInNeighborhood(const u32 type,
403  const Dir* dirs,
404  const u32 dirCount,
405  SPoint& outPoint) const;
406 
426  u32 FindEmptyInNeighborhood(const Dir* dirs,
427  const u32 dirCount,
428  SPoint& outPoint) const;
429 
446  u32 FindRandomInMoore(const u32 type, SPoint& outPoint) const;
447 
464  u32 FindRandomInVonNeumann(const u32 type, SPoint& outPoint) const;
465 
480  u32 FindEmptyInMoore(SPoint& outPoint) const;
481 
496  u32 FindEmptyInVonNeumann(SPoint& outPoint) const;
497 
523  void FindRandomAtoms(const u32 radius, const u32 count, ...) const;
524 
545  void FindRandomAtoms(const u32 count, ...) const;
546 
547  bool FindRandomAtomsInSubWindows(const u32 count, ...) const;
548 
549  private:
550 
551  void FindRandomAtoms(const u32 radius, const u32 count, va_list& list) const;
552  };
553 
554  const Dir MooreNeighborhood[8] =
555  {
556  Dirs::NORTH, Dirs::NORTHEAST, Dirs::EAST, Dirs::SOUTHEAST,
557  Dirs::SOUTH, Dirs::SOUTHWEST, Dirs::WEST, Dirs::NORTHWEST
558  };
559 
560  const Dir VonNeumannNeighborhood[4] =
561  {
562  Dirs::NORTH, Dirs::EAST, Dirs::SOUTH, Dirs::WEST
563  };
564 }
565 
566 #include "WindowScanner.tcc"
567 
568 #endif /* WINDOWSCANNER_H */
u32 CountEmptyAtoms(const u32 radius) const
Definition: WindowScanner.tcc:102
bool CanSeeAtomOfType(const u32 type, const u32 radius) const
Definition: WindowScanner.tcc:55
u32 CountInNeighborhood(const u32 type, const Dir *neighborhood, const u32 dirCount) const
Definition: WindowScanner.tcc:144
bool IsBorderingVonNeumann(const u32 type) const
Definition: WindowScanner.tcc:136
u32 FindEmptyInSubWindow(const SPoint *subWindow, const u32 subCount, SPoint &outPoint) const
Definition: WindowScanner.tcc:240
Definition: Random.h:45
bool FillIfEmpty(const SPoint &relative, const T &atom)
Definition: WindowScanner.tcc:49
WindowScanner(EventWindow< CC > &window)
Definition: WindowScanner.tcc:10
void FindRandomAtoms(const u32 radius, const u32 count,...) const
Definition: WindowScanner.tcc:319
u32 FindEmptyInVonNeumann(SPoint &outPoint) const
Definition: WindowScanner.tcc:311
bool IsBorderingMoore(const u32 type) const
Definition: WindowScanner.tcc:128
u32 FindRandomInVonNeumann(const u32 type, SPoint &outPoint) const
Definition: WindowScanner.tcc:294
u32 FindRandomInMoore(const u32 type, SPoint &outPoint) const
Definition: WindowScanner.tcc:285
u32 CountAtomsOfType(const u32 type, const u32 radius) const
Definition: WindowScanner.tcc:78
~WindowScanner()
Definition: WindowScanner.h:84
u32 FindRandomInSubWindow(const u32 type, const SPoint *subWindow, const u32 subCount, SPoint &outPoint) const
Definition: WindowScanner.tcc:218
Definition: ElementTable.h:43
u32 FindEmptyInMoore(SPoint &outPoint) const
Definition: WindowScanner.tcc:303
u32 FindRandomLocationOfType(const u32 type, SPoint &outPoint) const
Definition: WindowScanner.tcc:182
#define EVENT_WINDOW_SITES(radius)
Definition: MDist.h:46
Definition: WindowScanner.h:40
u32 CountMooreNeighbors(const u32 type) const
Definition: WindowScanner.tcc:166
u32 FindEmptyInNeighborhood(const Dir *dirs, const u32 dirCount, SPoint &outPoint) const
Definition: WindowScanner.tcc:274
bool IsBorderingNeighborhood(const u32 type, const Dir *neighborhood, const u32 dirCount) const
Definition: WindowScanner.tcc:108
u32 FindRandomInNeighborhood(const u32 type, const Dir *dirs, const u32 dirCount, SPoint &outPoint) const
Definition: WindowScanner.tcc:247
bool FillIfType(const SPoint &relative, const u32 type, const T &atom)
Definition: WindowScanner.tcc:17
bool FillIfNotType(const SPoint &relative, const u32 type, const T &atom)
Definition: WindowScanner.tcc:32
Definition: Point.h:45
u32 CountVonNeumannNeighbors(const u32 type) const
Definition: WindowScanner.tcc:174