CoordinatePolicy.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 
32 #ifndef COORD_POLICY_H_
33 #define COORD_POLICY_H_
34 
35 #include <drain/Log.h>
36 #include <drain/UniTuple.h>
37 #include <ostream>
38 #include <stdexcept>
39 
40 #include "drain/util/Frame.h"
41 #include "drain/util/Point.h"
42 #include "drain/util/Range.h"
43 #include "drain/util/StatusFlags.h"
44 #include "Geometry.h"
45 
46 namespace drain {
47 
48 
49 namespace image {
50 
51 
52 
53 //typedef unsigned short coord_pol_t;
54 
55 struct EdgePolicy {
56 
57  typedef unsigned short index_t;
58 
59  static const EdgePolicy::index_t UNDEFINED;// = 0;
60  static const EdgePolicy::index_t LIMIT; // = 1;
61  static const EdgePolicy::index_t WRAP; // = 2;
62  static const EdgePolicy::index_t MIRROR; // = 3;
63  static const EdgePolicy::index_t POLAR; // = 4;
64 
66 
67  static
68  const dict_t dict; // Unused, future option
69 
70 };
71 
72 
73 
74 //typedef drain::Dictionary<std::string,EdgePolicy::index_t> coord_policy_dict_t;
75 
76 
77 //typedef drain::GlobalFlags<EdgePolicy::index_t> coord_policy_flags;
78 
79 // Only 2D, or templated?
80 /*
81 struct CoordinatePolicyFlags {
82  static const EdgePolicy::index_t UNDEFINED = 0;
83  static const EdgePolicy::index_t LIMIT;
84  static const EdgePolicy::index_t WRAP;
85  static const EdgePolicy::index_t MIRROR;
86  static const EdgePolicy::index_t POLAR;
87 };
88 */
89 
90 /*
91 typedef enum { // consider GlobalFlagger
92  UNDEFINED = 0,
93  LIMIT = 1, // = constexpr drain::GlobalFlags<long>::add("LIMIT"),
94  WRAP = 2,
95  MIRROR = 3,
96  POLAR = 4
97 } EdgePolicy::index_t;
98 */
99 
100 //typedef drain::GlobalFlags<Coordinates> coord_policy_flags;
101 
103 
106 class CoordinatePolicy : public UniTuple<EdgePolicy::index_t,4> {
107 
108 public:
109 
110  EdgePolicy::index_t & xUnderFlowPolicy;
111  EdgePolicy::index_t & yUnderFlowPolicy;
112  EdgePolicy::index_t & xOverFlowPolicy;
113  EdgePolicy::index_t & yOverFlowPolicy;
114 
115 
116  // Don't use enum (difficult to export/import).
117 
118  //static const drain::FlaggerBase<EdgePolicy::index_t>::dict_t dict;
119 
120 
121  inline
122  CoordinatePolicy(EdgePolicy::index_t p = EdgePolicy::LIMIT) :
123  xUnderFlowPolicy(next()), yUnderFlowPolicy(next()), xOverFlowPolicy(next()), yOverFlowPolicy(next()) {
124  fill(p); // or set(p, p, p, p); // No auto fill.
125  };
126 
127  inline
128  CoordinatePolicy(const CoordinatePolicy & policy) : //v(4, LIMIT), xUnderFlowPolicy(v[0]), yUnderFlowPolicy(v[1]), xOverFlowPolicy(v[2]), yOverFlowPolicy(v[3]) {
129  xUnderFlowPolicy(next()), yUnderFlowPolicy(next()), xOverFlowPolicy(next()), yOverFlowPolicy(next()) {
130  assignSequence(policy);
131  };
132 
133  inline
134  CoordinatePolicy(EdgePolicy::index_t xUnderFlowPolicy, EdgePolicy::index_t yUnderFlowPolicy, EdgePolicy::index_t xOverFlowPolicy, EdgePolicy::index_t yOverFlowPolicy) : //v(4, LIMIT), xUnderFlowPolicy(v[0]), yUnderFlowPolicy(v[1]), xOverFlowPolicy(v[2]), yOverFlowPolicy(v[3]) {
135  xUnderFlowPolicy(next()), yUnderFlowPolicy(next()), xOverFlowPolicy(next()), yOverFlowPolicy(next()) {
136  set(xUnderFlowPolicy, yUnderFlowPolicy, xOverFlowPolicy, yOverFlowPolicy);
137  };
138 
139  inline
140  CoordinatePolicy & operator=(const CoordinatePolicy & policy){
141  assignSequence(policy);
142  return *this;
143  }
144 
145  inline
146  bool isSet(){
147  for (EdgePolicy::index_t p: tuple()){
148  if (p == EdgePolicy::UNDEFINED)
149  return false;
150  }
151  return true;
152  }
153 
154 
155 };
156 
157 std::ostream & operator<<(std::ostream & ostr, const CoordinatePolicy & policy);
158 
159 } // image
160 
161 } // drain
162 #endif
163 
164 // Drain
Two-way mapping between strings and objects of template class T.
Definition: Dictionary.h:63
tuplebase_t & assignSequence(T &sequence, bool LENIENT=false)
Proposed for tuples only; derived classes should not shadow this.
Definition: TupleBase.h:244
void fill(S i)
Set all the elements to i.
Definition: TupleBase.h:272
Tuple of N elements of type T.
Definition: UniTuple.h:65
Policies for coordinate underflows and overflows.
Definition: CoordinatePolicy.h:106
Definition: DataSelector.cpp:1277
Definition: CoordinatePolicy.h:55