-
Notifications
You must be signed in to change notification settings - Fork 0
/
DgDmdD8Grid2DS.cpp
237 lines (191 loc) · 6.85 KB
/
DgDmdD8Grid2DS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
////////////////////////////////////////////////////////////////////////////////
//
// DgDmdD8Grid2DS.cpp: DgDmdD8Grid2DS class implementation
//
// Version 6.1 - Kevin Sahr, 5/23/13
//
////////////////////////////////////////////////////////////////////////////////
#include <cmath>
#include "DgContCartRF.h"
#include "DgDiscRF.h"
#include "DgDmdD8Grid2D.h"
#include "DgDmdD8Grid2DS.h"
////////////////////////////////////////////////////////////////////////////////
DgDmdD8Grid2DS::DgDmdD8Grid2DS (DgRFNetwork& networkIn,
const DgRF<DgDVec2D, long double>& backFrameIn, int nResIn,
unsigned int apertureIn, bool isCongruentIn, bool isAlignedIn,
const string& nameIn)
: DgDiscRFS2D (networkIn, backFrameIn, nResIn, apertureIn,
isCongruentIn, isAlignedIn, nameIn)
{
// determine the radix
radix_ = static_cast<int>(sqrt(static_cast<float>(aperture())));
if (static_cast<unsigned int>(radix() * radix()) != aperture())
{
report(
"DgDmdD8Grid2DS::DgDmdD8Grid2DS() aperture must be a perfect square",
DgBase::Fatal);
}
if (isAligned() && radix() != 2 && radix() != 3)
{
report("DgDmdD4Grid2DS::DgDmdD4Grid2DS() only aligned apertures 4 and 9 "
" parent/children operators fully implemented", DgBase::Warning);
}
// do the grids
long double fac = 1;
DgDVec2D trans;
if (isCongruent())
{
trans = DgDVec2D(-0.5, -0.5);
}
else if (isAligned())
{
trans = DgDVec2D(0.0, 0.0);
if (radix() != 2 && radix() != 3)
{
report(
"DgDmdD8Grid2DS::DgDmdD8Grid2DS() only aligned apertures 2 and 3 "
" are implemented", DgBase::Fatal);
}
}
else
{
report("DgDmdD8Grid2DS::DgDmdD8Grid2DS() grid system must be either "
"congruent, aligned, or both", DgBase::Fatal);
}
for (int i = 0; i < nRes(); i++)
{
string newName = name() + "_" + dgg::util::to_string(i);
//cout << newName << " " << fac << ' ' << trans << endl;
DgContCartRF* ccRF = new DgContCartRF(network(), newName + string("bf"));
new Dg2WayContAffineConverter(backFrame(), *ccRF, (long double) fac, 0.0,
trans);
(*grids_)[i] = new DgDmdD8Grid2D(network(), *ccRF, newName);
new Dg2WayResAddConverter<DgIVec2D, DgDVec2D, long double>
(*this, *(grids()[i]), i);
fac *= radix();
}
} // DgDmdD8Grid2DS::DgDmdD8Grid2DS
////////////////////////////////////////////////////////////////////////////////
DgDmdD8Grid2DS::DgDmdD8Grid2DS (const DgDmdD8Grid2DS& rf)
: DgDiscRFS2D (rf)
{
report("DgDmdD8Grid2DS::operator=() not implemented yet", DgBase::Fatal);
} // DgDmdD8Grid2DS::DgDmdD8Grid2DS
////////////////////////////////////////////////////////////////////////////////
DgDmdD8Grid2DS::~DgDmdD8Grid2DS (void)
{
for (unsigned long i = 0; i < grids().size(); i++)
delete (*grids_)[i];
delete grids_;
} // DgDmdD8Grid2DS::~DgDmdD8Grid2DS
////////////////////////////////////////////////////////////////////////////////
DgDmdD8Grid2DS&
DgDmdD8Grid2DS::operator= (const DgDmdD8Grid2DS& rf)
{
report("DgDmdD8Grid2DS::operator=() ", DgBase::Fatal);
return *this;
} // DgDmdD8Grid2DS& DgDmdD8Grid2DS::operator=
////////////////////////////////////////////////////////////////////////////////
void
DgDmdD8Grid2DS::setAddParents (const DgResAdd<DgIVec2D>& add,
DgLocVector& vec) const
{
//cout << " setAddParents: " << add << endl;
if (isCongruent() || radix() == 3)
{
DgLocation* tmpLoc = makeLocation(add);
grids()[add.res() - 1]->convert(tmpLoc);
convert(tmpLoc);
vec.push_back(*tmpLoc);
delete tmpLoc;
}
else // must be aligned aperture 4
{
// vertices lie in parents
DgLocation* tmpLoc = makeLocation(add);
DgPolygon* verts = makeVertices(*tmpLoc);
delete tmpLoc;
//cout << " verts 1: " << *verts << endl;
grids()[add.res() - 1]->convert(*verts);
//cout << " verts 2: " << *verts << endl;
convert(*verts);
//cout << " verts 3: " << *verts << endl;
for (int i = 0; i < verts->size(); i++)
{
bool found = false;
for (int j = 0; j < vec.size(); j++)
{
//cout << " " << i << " " << j << " " << (*verts)[i] << " " << vec[j];
if ((*verts)[i] == vec[j])
{
//cout << " YES" << endl;
found = true;
break;
}
//cout << " NO" << endl;
}
if (!found) vec.push_back((*verts)[i]);
}
//cout << " parents: " << vec << endl;
delete verts;
}
} // void DgDmdD8Grid2DS::setAddParents
////////////////////////////////////////////////////////////////////////////////
void
DgDmdD8Grid2DS::setAddInteriorChildren (const DgResAdd<DgIVec2D>& add,
DgLocVector& vec) const
{
if (isCongruent() || radix() == 3)
{
const DgIVec2D& lowerLeft = add.address() * radix();
vector<DgAddressBase*>& v = vec.addressVec();
for (int i = 0; i < radix(); i++)
{
for (int j = 0; j < radix(); j++)
{
v.push_back(new DgAddress< DgResAdd<DgIVec2D> >(
DgResAdd<DgIVec2D>(DgIVec2D(lowerLeft.i() + i, lowerLeft.j() + j),
add.res() + 1)));
}
}
}
else // must be aligned aperture 4
{
// only center square is interior
DgLocation* tmpLoc = makeLocation(add);
grids()[add.res() + 1]->convert(tmpLoc);
vec.push_back(*tmpLoc);
delete tmpLoc;
}
} // void DgDmdD8Grid2DS::setAddInteriorChildren
////////////////////////////////////////////////////////////////////////////////
void
DgDmdD8Grid2DS::setAddBoundaryChildren (const DgResAdd<DgIVec2D>& add,
DgLocVector& vec) const
{
if (isCongruent() || radix() == 3)
{
// no boundary children in this topology; leave vec empty
}
else // must be aligned aperture 4
{
DgLocation* tmpLoc = makeLocation(add);
grids()[add.res() + 1]->convert(tmpLoc);
convert(tmpLoc);
setNeighbors(*tmpLoc, vec);
delete tmpLoc;
}
} // void DgDmdD8Grid2DS::setAddBoundaryChildren
////////////////////////////////////////////////////////////////////////////////
void
DgDmdD8Grid2DS::setAddAllChildren (const DgResAdd<DgIVec2D>& add,
DgLocVector& vec) const
{
setAddInteriorChildren(add, vec);
DgLocVector bndVec(vec.rf());
setAddBoundaryChildren(add, bndVec);
for (int i = 0; i < bndVec.size(); i++) vec.push_back(bndVec[i]);
} // void DgDmdD8Grid2DS::setAddAllChildren
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////