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