NEST  2.6.0,not_revisioned_source_dir@0
mask.h
Go to the documentation of this file.
1 /*
2  * 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 MASK_H
24 #define 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 "exceptions.h"
32 #include "topologymodule.h"
33 
34 namespace nest
35 {
36  class TopologyModule;
37 
42  {
43  public:
47  virtual ~AbstractMask()
48  {}
49 
53  virtual bool inside(const std::vector<double_t> &) const = 0;
54 
58  virtual DictionaryDatum get_dict() const
59  { throw KernelException("Can not convert mask to dict"); }
60 
66  virtual AbstractMask * intersect_mask(const AbstractMask & other) const = 0;
67 
73  virtual AbstractMask * union_mask(const AbstractMask & other) const = 0;
74 
80  virtual AbstractMask * minus_mask(const AbstractMask & other) const = 0;
81 
82  };
83 
85 
89  template<int D>
90  class Mask : public AbstractMask
91  {
92  public:
94  {}
95 
99  virtual bool inside(const Position<D> &) const = 0;
100 
104  bool inside(const std::vector<double_t> &pt) const;
105 
111  virtual bool inside(const Box<D> &) const = 0;
112 
118  virtual bool outside(const Box<D> &b) const;
119 
124  virtual Box<D> get_bbox() const = 0;
125 
130  virtual Mask * clone() const = 0;
131 
133  AbstractMask * union_mask(const AbstractMask & other) const;
134  AbstractMask * minus_mask(const AbstractMask & other) const;
135  };
136 
140  template<int D>
141  class AllMask : public Mask<D>
142  {
143  public:
144 
146  {}
147 
148  using Mask<D>::inside;
149 
153  bool inside(const Position<D> &) const
154  { return true; }
155 
159  bool inside(const Box<D> &) const
160  { return true; }
161 
165  bool outside(const Box<D> &) const
166  { return false; }
167 
168  Box<D> get_bbox() const
169  {
170  const double inf = std::numeric_limits<double>::infinity();
171  return Box<D>(Position<D>(-inf,-inf), Position<D>(inf,inf));
172  }
173 
174  Mask<D> * clone() const
175  { return new AllMask(); }
176  };
177 
181  template<int D>
182  class BoxMask : public Mask<D>
183  {
184  public:
185 
191  BoxMask(const DictionaryDatum&);
192 
194 
196  {}
197 
198  using Mask<D>::inside;
199 
203  bool inside(const Position<D> &p) const;
204 
208  bool inside(const Box<D> &b) const;
209 
213  bool outside(const Box<D> &b) const;
214 
215  Box<D> get_bbox() const;
216 
217  DictionaryDatum get_dict() const;
218 
219  Mask<D> * clone() const;
220 
224  static Name get_name();
225 
226  protected:
229  };
230 
234  template<int D>
235  class BallMask : public Mask<D>
236  {
237  public:
243  center_(center), radius_(radius)
244  {}
245 
251  BallMask(const DictionaryDatum&);
252 
254  {}
255 
256  using Mask<D>::inside;
257 
261  bool inside(const Position<D> &p) const;
262 
266  bool inside(const Box<D> &) const;
267 
271  bool outside(const Box<D> &b) const;
272 
273  Box<D> get_bbox() const;
274 
275  DictionaryDatum get_dict() const;
276 
277  Mask<D> * clone() const;
278 
282  static Name get_name();
283 
284  protected:
287  };
288 
292  template<int D>
293  class IntersectionMask : public Mask<D> {
294  public:
295 
300  IntersectionMask(const Mask<D> &m1, const Mask<D> &m2):
301  mask1_(m1.clone()), mask2_(m2.clone())
302  {}
303 
308  Mask<D>(m), mask1_(m.mask1_->clone()), mask2_(m.mask2_->clone())
309  {}
310 
312  { delete mask1_; delete mask2_; }
313 
314  bool inside(const Position<D> &p) const;
315 
316  bool inside(const Box<D> &b) const;
317 
318  bool outside(const Box<D> &b) const;
319 
320  Box<D> get_bbox() const;
321 
322  Mask<D> * clone() const;
323 
324  protected:
326  };
327 
331  template<int D>
332  class UnionMask : public Mask<D> {
333  public:
334 
339  UnionMask(const Mask<D> &m1, const Mask<D> &m2):
340  mask1_(m1.clone()), mask2_(m2.clone())
341  {}
342 
346  UnionMask(const UnionMask &m):
347  Mask<D>(m), mask1_(m.mask1_->clone()), mask2_(m.mask2_->clone())
348  {}
349 
351  { delete mask1_; delete mask2_; }
352 
353  bool inside(const Position<D> &p) const;
354 
355  bool inside(const Box<D> &b) const;
356 
357  bool outside(const Box<D> &b) const;
358 
359  Box<D> get_bbox() const;
360 
361  Mask<D> * clone() const;
362 
363  protected:
365  };
366 
370  template<int D>
371  class DifferenceMask : public Mask<D> {
372  public:
373 
378  DifferenceMask(const Mask<D> &m1, const Mask<D> &m2):
379  mask1_(m1.clone()), mask2_(m2.clone())
380  {}
381 
386  Mask<D>(m), mask1_(m.mask1_->clone()), mask2_(m.mask2_->clone())
387  {}
388 
390  { delete mask1_; delete mask2_; }
391 
392  bool inside(const Position<D> &p) const;
393 
394  bool inside(const Box<D> &b) const;
395 
396  bool outside(const Box<D> &b) const;
397 
398  Box<D> get_bbox() const;
399 
400  Mask<D> * clone() const;
401 
402  protected:
404  };
405 
406 
410  template<int D>
411  class ConverseMask : public Mask<D> {
412  public:
417  ConverseMask(const Mask<D> &m): m_(m.clone()) {}
418 
422  ConverseMask(const ConverseMask &m): Mask<D>(m), m_(m.m_->clone()) {}
423 
425  { delete m_; }
426 
427  bool inside(const Position<D> &p) const;
428 
429  bool inside(const Box<D> &b) const;
430 
431  bool outside(const Box<D> &b) const;
432 
433  Box<D> get_bbox() const;
434 
435  Mask<D> * clone() const;
436 
437  protected:
439  };
440 
441 
445  template<int D>
446  class AnchoredMask : public Mask<D> {
447  public:
452  AnchoredMask(const Mask<D> &m, Position<D> anchor): m_(m.clone()), anchor_(anchor) {}
453 
457  AnchoredMask(const AnchoredMask &m): Mask<D>(m), m_(m.m_->clone()), anchor_(m.anchor_) {}
458 
460  { delete m_; }
461 
462  bool inside(const Position<D> &p) const;
463 
464  bool inside(const Box<D> &b) const;
465 
466  bool outside(const Box<D> &b) const;
467 
468  Box<D> get_bbox() const;
469 
470  DictionaryDatum get_dict() const;
471 
472  Mask<D> * clone() const;
473 
474  protected:
477  };
478 
479  template<>
480  inline
482  {
483  return names::rectangular;
484  }
485 
486  template<>
487  inline
489  {
490  return names::box;
491  }
492 
493  template<int D>
495  {
496  lower_left_ = getValue<std::vector<double_t> >(d, names::lower_left);
497  upper_right_ = getValue<std::vector<double_t> >(d, names::upper_right);
498  if ( not ( lower_left_ < upper_right_ ) )
499  throw BadProperty("topology::BoxMask<D>: "
500  "Upper right must be strictly to the right and above lower left.");
501  }
502 
503  template<int D>
504  inline
506  lower_left_(lower_left), upper_right_(upper_right)
507  {}
508 
509  template<>
510  inline
512  {
513  return names::circular;
514  }
515 
516  template<>
517  inline
519  {
520  return names::spherical;
521  }
522 
523  template<int D>
525  {
526  radius_ = getValue<double_t>(d, names::radius);
527  if ( radius_ <= 0 )
528  throw BadProperty("topology::BallMask<D>: "
529  "radius > 0 required.");
530 
531  if (d->known(names::anchor)) {
532  center_ = getValue<std::vector<double_t> >(d, names::anchor);
533  }
534  }
535 
536 } // namespace nest
537 
538 #endif
ConverseMask(const Mask< D > &m)
Construct the converse of the two given mask.
Definition: mask.h:417
virtual AbstractMask * union_mask(const AbstractMask &other) const =0
Create the union of this mask with another.
bool outside(const Box< D > &b) const
Definition: mask_impl.h:91
Mask combining two masks with a minus operation, the difference.
Definition: mask.h:371
virtual bool outside(const Box< D > &b) const
Definition: mask_impl.h:68
Box< D > get_bbox() const
The whole mask is inside (i.e., false everywhere outside) the bounding box.
Definition: mask_impl.h:271
BallMask(Position< D > center, double_t radius)
Definition: mask.h:242
Mask oriented in the opposite direction.
Definition: mask.h:411
IntersectionMask(const IntersectionMask &m)
Copy constructor.
Definition: mask.h:307
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
bool inside(const Position< D > &p) const
Definition: mask_impl.h:253
Mask< D > * m_
Definition: mask.h:475
~IntersectionMask()
Definition: mask.h:311
virtual AbstractMask * minus_mask(const AbstractMask &other) const =0
Create the difference of this mask and another.
Box< D > get_bbox() const
The whole mask is inside (i.e., false everywhere outside) the bounding box.
Definition: mask_impl.h:233
ConverseMask(const ConverseMask &m)
Copy constructor.
Definition: mask.h:422
Mask shifted by an anchor.
Definition: mask.h:446
Mask< D > * clone() const
Clone method.
Definition: mask_impl.h:198
Mask< D > * mask2_
Definition: mask.h:364
const Name spherical("spherical")
Definition: topology_names.h:86
bool inside(const Position< D > &p) const
Definition: mask_impl.h:79
~BoxMask()
Definition: mask.h:195
UnionMask(const UnionMask &m)
Copy constructor.
Definition: mask.h:346
DictionaryDatum get_dict() const
Definition: mask_impl.h:383
const Name lower_left("lower_left")
Definition: topology_names.h:66
bool outside(const Box< D > &) const
Definition: mask.h:165
Represent strings by ints to facilitate fast comparison.
Definition: name.h:53
Mask which covers all of space.
Definition: mask.h:141
Position< D > anchor_
Definition: mask.h:476
Box< D > get_bbox() const
The whole mask is inside (i.e., false everywhere outside) the bounding box.
Definition: mask_impl.h:101
virtual Mask * clone() const =0
Clone method.
bool inside(const Position< D > &p) const
Definition: mask_impl.h:291
Box< D > get_bbox() const
The whole mask is inside (i.e., false everywhere outside) the bounding box.
Definition: mask_impl.h:187
Mask< D > * clone() const
Clone method.
Definition: mask_impl.h:377
Mask< D > * clone() const
Clone method.
Definition: mask_impl.h:315
Mask< D > * clone() const
Clone method.
Definition: mask_impl.h:107
Mask defining a circular or spherical region.
Definition: mask.h:235
virtual bool inside(const Position< D > &) const =0
virtual bool inside(const std::vector< double_t > &) const =0
virtual DictionaryDatum get_dict() const
Definition: mask.h:58
bool inside(const Position< D > &p) const
Definition: mask_impl.h:321
Position< D > lower_left_
Definition: mask.h:227
Position< D > upper_right_
Definition: mask.h:228
~BallMask()
Definition: mask.h:253
Mask defining a box region.
Definition: mask.h:182
const Name radius("radius")
Definition: topology_names.h:68
Abstract base class for masks with given dimension.
Definition: mask.h:90
bool inside(const Position< D > &p) const
Definition: mask_impl.h:352
const Name anchor("anchor")
Definition: topology_names.h:50
bool outside(const Box< D > &b) const
Definition: mask_impl.h:174
const Name box("box")
Definition: topology_names.h:88
static Name get_name()
bool inside(const Box< D > &) const
Definition: mask.h:159
const Name center("center")
Definition: topology_names.h:48
DifferenceMask(const Mask< D > &m1, const Mask< D > &m2)
Construct the difference of the two given masks.
Definition: mask.h:378
DifferenceMask(const DifferenceMask &m)
Copy constructor.
Definition: mask.h:385
const Name other("other")
Node type.
Definition: nest_names.h:216
Base class for all Kernel exceptions.
Definition: exceptions.h:54
Mask< D > * mask2_
Definition: mask.h:403
AnchoredMask(const Mask< D > &m, Position< D > anchor)
Construct the converse of the two given mask.
Definition: mask.h:452
A box is defined by the lower left corner (minimum coordinates) and the upper right corner (maximum c...
Definition: position.h:289
const Name rectangular("rectangular")
Definition: topology_names.h:87
AbstractMask * union_mask(const AbstractMask &other) const
Create the union of this mask with another.
Definition: mask_impl.h:42
UnionMask(const Mask< D > &m1, const Mask< D > &m2)
Construct the union of the two given masks.
Definition: mask.h:339
Position< D > center_
Definition: mask.h:285
virtual AbstractMask * intersect_mask(const AbstractMask &other) const =0
Create the intersection of this mask with another.
Mask< D > * mask1_
Definition: mask.h:325
bool outside(const Box< D > &b) const
Definition: mask_impl.h:333
Mask< D > * mask2_
Definition: mask.h:325
bool outside(const Box< D > &b) const
Definition: mask_impl.h:227
virtual ~AbstractMask()
Virtual destructor.
Definition: mask.h:47
Mask< D > * m_
Definition: mask.h:438
~Mask()
Definition: mask.h:93
BoxMask(const DictionaryDatum &)
Parameters that should be in the dictionary: lower_left - Position of lower left corner (array of dou...
Definition: mask.h:494
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition: exceptions.h:420
bool outside(const Box< D > &b) const
Definition: mask_impl.h:265
Box< D > get_bbox() const
The whole mask is inside (i.e., false everywhere outside) the bounding box.
Definition: mask_impl.h:339
Mask< D > * mask1_
Definition: mask.h:364
double double_t
Double precision floating point numbers.
Definition: nest.h:93
bool outside(const Box< D > &b) const
Definition: mask_impl.h:364
Mask< D > * clone() const
Clone method.
Definition: mask_impl.h:346
AbstractMask * minus_mask(const AbstractMask &other) const
Create the difference of this mask and another.
Definition: mask_impl.h:52
const Name b("b")
Specific to Brette & Gerstner 2005 (aeif_cond-*)
Definition: nest_names.h:58
AbstractMask * intersect_mask(const AbstractMask &other) const
Create the intersection of this mask with another.
Definition: mask_impl.h:32
AnchoredMask(const AnchoredMask &m)
Copy constructor.
Definition: mask.h:457
Box< D > get_bbox() const
The whole mask is inside (i.e., false everywhere outside) the bounding box.
Definition: mask.h:168
IntersectionMask(const Mask< D > &m1, const Mask< D > &m2)
Construct the intersection of the two given masks.
Definition: mask.h:300
Mask< D > * clone() const
Clone method.
Definition: mask_impl.h:285
Mask< D > * mask1_
Definition: mask.h:403
Box< D > get_bbox() const
The whole mask is inside (i.e., false everywhere outside) the bounding box.
Definition: mask_impl.h:370
Mask combining two masks with a Boolean AND, the intersection.
Definition: mask.h:293
Default types used by the NEST kernel.
~UnionMask()
Definition: mask.h:350
bool outside(const Box< D > &b) const
Definition: mask_impl.h:303
~ConverseMask()
Definition: mask.h:424
Mask combining two masks with a Boolean OR, the sum.
Definition: mask.h:332
virtual Box< D > get_bbox() const =0
The whole mask is inside (i.e., false everywhere outside) the bounding box.
Abstract base class for masks with unspecified dimension.
Definition: mask.h:41
bool inside(const Position< D > &p) const
Definition: mask_impl.h:215
Mask< D > * clone() const
Clone method.
Definition: mask_impl.h:247
DictionaryDatum get_dict() const
Definition: mask_impl.h:204
bool inside(const Position< D > &) const
Definition: mask.h:153
const Name p("p")
current release probability (Tsodyks2_connection)
Definition: nest_names.h:218
~AllMask()
Definition: mask.h:145
lockPTRDatum< AbstractMask,&TopologyModule::MaskType > MaskDatum
Definition: mask.h:84
const Name circular("circular")
Definition: topology_names.h:85
const Name upper_right("upper_right")
Definition: topology_names.h:67
~AnchoredMask()
Definition: mask.h:459
Mask< D > * clone() const
Clone method.
Definition: mask.h:174
bool inside(const Position< D > &p) const
Definition: mask_impl.h:124
Box< D > get_bbox() const
The whole mask is inside (i.e., false everywhere outside) the bounding box.
Definition: mask_impl.h:309
~DifferenceMask()
Definition: mask.h:389
static Name get_name()
DictionaryDatum get_dict() const
Definition: mask_impl.h:113
double_t radius_
Definition: mask.h:286