NEST main@caf0ae8
 
Loading...
Searching...
No Matches
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// Includes from nestkernel:
27#include "mask.h"
28#include "nest_names.h"
29#include "nest_types.h"
30#include "position.h"
31
32namespace nest
33{
38template < int D >
39class GridMask : public AbstractMask
40{
41public:
47 GridMask( const Dictionary& d );
48
49 bool
50 inside( const std::vector< double >& ) const override
51 {
52 throw KernelException( "Grid mask must be applied to a grid layer." );
53 }
54
55 void set_anchor( const Position< D, int >& );
56
57 Dictionary get_dict() const override;
58
60 clone() const
61 {
62 return new GridMask( *this );
63 }
64
68 static std::string get_name();
69
71 intersect_mask( const AbstractMask& ) const override
72 {
73 throw KernelException( "Grid masks can not be combined." );
74 }
75
77 union_mask( const AbstractMask& ) const override
78 {
79 throw KernelException( "Grid masks can not be combined." );
80 }
81
83 minus_mask( const AbstractMask& ) const override
84 {
85 throw KernelException( "Grid masks can not be combined." );
86 }
87
90 {
91 return upper_left_;
92 }
93
96 {
97 return lower_right_;
98 }
99
100protected:
103};
104
105template < int D >
107{
108 std::vector< long > shape = d.get< std::vector< long > >( names::shape );
109
110 if ( D == 2 )
111 {
112 lower_right_ = Position< D, int >( shape[ 0 ], shape[ 1 ] );
113 }
114 else if ( D == 3 )
115 {
116 lower_right_ = Position< D, int >( shape[ 0 ], shape[ 1 ], shape[ 2 ] );
117 }
118 else
119 {
120 throw BadProperty( "Grid mask must be 2- or 3-dimensional." );
121 }
122}
123
124template <>
125inline std::string
127{
128 return names::grid;
129}
130
131template <>
132inline std::string
137
138template < int D >
141{
142 Dictionary d;
143 Dictionary maskd;
144 d[ get_name() ] = maskd;
145
146 long shape_x = lower_right_[ 0 ] - upper_left_[ 0 ];
147 long shape_y = lower_right_[ 1 ] - upper_left_[ 1 ];
148 std::vector< long > shape_dim { shape_x, shape_y };
149
150 if ( D == 3 )
151 {
152 long shape_z = lower_right_[ 2 ] - upper_left_[ 2 ];
153 shape_dim.push_back( shape_z );
154 }
155 maskd[ names::shape ] = shape_dim;
156
157 return d;
158}
159
160template < int D >
161void
163{
164 lower_right_ = lower_right_ - upper_left_ - anchor;
165 upper_left_ = -anchor;
166}
167
168} // namespace nest
169
170#endif
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Abstract base class for masks with unspecified dimension.
Definition mask.h:51
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition exceptions.h:680
Mask defined in terms of grid points rather than spacial coordinates.
Definition grid_mask.h:40
GridMask(const Dictionary &d)
Parameters: shape - size in grid coordinates (length 2 for 2D layers or length 3 for 3D layers)
Definition grid_mask.h:106
Dictionary get_dict() const override
Definition grid_mask.h:140
void set_anchor(const Position< D, int > &)
Definition grid_mask.h:162
Position< D, int > get_lower_right() const
Definition grid_mask.h:95
Position< D, int > lower_right_
Definition grid_mask.h:102
bool inside(const std::vector< double > &) const override
Definition grid_mask.h:50
static std::string get_name()
Position< D, int > upper_left_
Definition grid_mask.h:101
AbstractMask * intersect_mask(const AbstractMask &) const override
Create the intersection of this mask with another.
Definition grid_mask.h:71
Position< D, int > get_upper_left() const
Definition grid_mask.h:89
AbstractMask * union_mask(const AbstractMask &) const override
Create the union of this mask with another.
Definition grid_mask.h:77
GridMask< D > * clone() const
Definition grid_mask.h:60
AbstractMask * minus_mask(const AbstractMask &) const override
Create the difference of this mask and another.
Definition grid_mask.h:83
Base class for all Kernel exceptions.
Definition exceptions.h:65
const std::string shape("shape")
const std::string grid3d("grid3d")
const std::string grid("grid")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33