NEST  2.6.0,not_revisioned_source_dir@0
grid_mask.h
Go to the documentation of this file.
1 /*
2  * grid_mask.h
3  *
4  * This file is part of NEST.
5  *
6  * Copyright (C) 2004 The NEST Initiative
7  *
8  * NEST is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * NEST is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef GRID_MASK_H
24 #define GRID_MASK_H
25 
26 #include "nest.h"
27 #include "topology_names.h"
28 #include "position.h"
29 #include "dictdatum.h"
30 #include "dictutils.h"
31 #include "topologymodule.h"
32 #include "mask.h"
33 
34 namespace nest
35 {
40  template<int D>
41  class GridMask : public AbstractMask
42  {
43  public:
50  GridMask(const DictionaryDatum& d);
51 
52  bool inside(const std::vector<double_t> &) const
53  { throw KernelException("Grid mask must be applied to a grid layer."); }
54 
55  void set_anchor(const Position<D,int_t>&);
56 
57  DictionaryDatum get_dict() const;
58 
59  GridMask<D> * clone() const
60  { return new GridMask(*this); }
61 
65  static Name get_name();
66 
68  { throw KernelException("Grid masks can not be combined."); }
69 
71  { throw KernelException("Grid masks can not be combined."); }
72 
74  { throw KernelException("Grid masks can not be combined."); }
75 
77  { return upper_left_; }
78 
80  { return lower_right_; }
81 
82  protected:
85  };
86 
87  template<int D>
89  {
92  if (D==3) {
94  lower_right_ = Position<D,int_t>(columns,rows,layers);
95  } else if (D==2) {
96  lower_right_ = Position<D,int_t>(columns,rows);
97  } else {
98  throw BadProperty("Grid mask must be 2- or 3-dimensional.");
99  }
100  }
101 
102  template<>
103  inline
105  {
106  return names::grid;
107  }
108 
109  template<>
110  inline
112  {
113  return names::grid3d;
114  }
115 
116  template<int D>
118  {
120  DictionaryDatum maskd(new Dictionary);
121  def<DictionaryDatum>(d, get_name(), maskd);
122  def<long>(maskd, names::columns, lower_right_[0]-upper_left_[0]);
123  def<long>(maskd, names::rows, lower_right_[1]-upper_left_[1]);
124  if (D>=3) {
125  def<long>(maskd, names::layers, lower_right_[2]-upper_left_[2]);
126  }
127  return d;
128  }
129 
130  template<int D>
132  {
133  lower_right_ = lower_right_ - upper_left_ - anchor;
134  upper_left_ = -anchor;
135  }
136 
137 } // namespace nest
138 
139 #endif
140 
int int_t
Integer number with at least 16 bit.
Definition: nest.h:95
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
Position< D, int_t > lower_right_
Definition: grid_mask.h:84
AbstractMask * intersect_mask(const AbstractMask &) const
Create the intersection of this mask with another.
Definition: grid_mask.h:67
const Name layers("layers")
Definition: topology_names.h:81
Represent strings by ints to facilitate fast comparison.
Definition: name.h:53
Position< D, int_t > get_upper_left() const
Definition: grid_mask.h:76
Position< D, int_t > get_lower_right() const
Definition: grid_mask.h:79
A class that associates names and tokens.
Definition: dict.h:45
const Name anchor("anchor")
Definition: topology_names.h:50
Base class for all Kernel exceptions.
Definition: exceptions.h:54
AbstractMask * minus_mask(const AbstractMask &) const
Create the difference of this mask and another.
Definition: grid_mask.h:73
const Name grid3d("grid3d")
Definition: topology_names.h:92
bool inside(const std::vector< double_t > &) const
Definition: grid_mask.h:52
static Name get_name()
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition: exceptions.h:420
Position< D, int_t > upper_left_
Definition: grid_mask.h:83
DictionaryDatum get_dict() const
Definition: grid_mask.h:117
const Name columns("columns")
Definition: topology_names.h:43
Mask defined in terms of grid points rather than spacial coordinates.
Definition: grid_mask.h:41
void set_anchor(const Position< D, int_t > &)
Definition: grid_mask.h:131
GridMask< D > * clone() const
Definition: grid_mask.h:59
GridMask(const DictionaryDatum &d)
Parameters: columns - horizontal size in grid coordinates rows - vertical size in grid coordinates la...
Definition: grid_mask.h:88
const Name grid("grid")
Definition: topology_names.h:91
Default types used by the NEST kernel.
const Name rows("rows")
Number of rows in a layer or mask.
Definition: topology_names.h:42
AbstractMask * union_mask(const AbstractMask &) const
Create the union of this mask with another.
Definition: grid_mask.h:70
long getValue< long >(const Token &t)
Definition: tokenutils.cc:36
Abstract base class for masks with unspecified dimension.
Definition: mask.h:41