-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFollow.h
executable file
·346 lines (284 loc) · 13.5 KB
/
Follow.h
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#if _MSC_VER
#pragma once
#endif
#ifndef FOLLOW_H
#define FOLLOW_H
#include "Rn_Path.h"
#include "Glitch.h"
#include "triple.h"
#include "LRL_Cell.h"
#include "CellInputData.h"
#include "Delone.h"
#include "B4.h"
#include "D7Dist_.hpp"
#include "FollowerConstants.h"
#include "NCDist_.hpp"
#include "ProjectorTools.h"
#include "Reducer.h"
#include "S6M_SellingReduce.h"
#include <algorithm>
#include <cassert>
#include <list>
#include <typeinfo>
#include <utility>
template<typename TVEC, typename TMAT>
class Follow
{
public:
Follow(const TVEC& v1, const TVEC& v2)
: m_steps(-1)
, m_rnPath()
, m_whichComponentsToPlot(-1, -1)
, m_seconds2ComputerFrame(-1.0)
, m_glitches()
/*-------------------------------------------------------------------------------------*/
{
m_rnPath.AddProbe(v1);
m_rnPath.AddSecondProbe(v2);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
TVEC GetProbe(void) const {
return(m_rnPath.GetProbe());
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
TVEC GetSecondProbe(void) const {
return(m_rnPath.GetSecondProbe());
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// walk thru a set of perturbed vectors
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
Follow& Procession(void) {
Mat66 m;
const double tend(double(m_steps - 1L));
TVEC probe;
probe = m_rnPath.GetProbe();
int reduced;
G6 niggliReduced_1;
D7 d7_niggliReduced_1;
niggliReduced_1 = m_rnPath.GetSecondProbe();
G6 test;
test = Reducer::Reduce(niggliReduced_1);
if (!test.GetValid()) throw;
D7 d7_g6DeloneReduced_1;
G6 g6DeloneReduced_1;
CS6M_G6toD7(niggliReduced_1,d7_niggliReduced_1);
CS6M_D7Reduce(d7_niggliReduced_1,d7_g6DeloneReduced_1,reduced);
if (reduced) {
CS6M_D7toG6(d7_g6DeloneReduced_1,g6DeloneReduced_1)
}
double g6NiggliReducedArray_1[6], d7DeloneReducedArray_1[7];
double g6NiggliReducedArray_2[6], d7DeloneReducedArray_2[7];
ProjectorTools::ConvertG6ToArray(niggliReduced_1, g6NiggliReducedArray_1);
ProjectorTools::ConvertD7ToArray(D7(g6DeloneReduced_1), d7DeloneReducedArray_1);
for (long istep = 0; istep < m_steps; ++istep) {
int reduced6, reduced7;
const double t(double(istep) / tend);
TVEC vNext;
vNext = TVEC(TVEC((1.0 - t)*probe) + TVEC(t*niggliReduced_1));
G6 g6vNext(vNext);
D7 d7_g6vNext;
G6 g6NiggliReduced_2, g6DeloneReduced_2;
D7 d7_g6DeloneReduced_2;
CS6M_G6Reduce(g6vNext,g6NiggliReduced_2,reduced6);
CS6M_G6toD7(g6vNext,d7_g6vNext);
CS6M_D7Reduce(d7_g6vNext,d7_g6DeloneReduced_2,reduced7);
CS6M_D7toG6(d7_g6DeloneReduced_2,g6DeloneReduced_2);
if (reduced6&&reduced7) {
ProjectorTools::ConvertG6ToArray(g6NiggliReduced_2, g6NiggliReducedArray_2);
ProjectorTools::ConvertD7ToArray(D7(g6DeloneReduced_2), d7DeloneReducedArray_2);
const double dist6 = NCDist_<double[6], double[6] >(g6NiggliReducedArray_1, g6NiggliReducedArray_2);
const double dist7 = D7Dist_<double[7], double[7] >(d7DeloneReducedArray_1, d7DeloneReducedArray_2);
//double dist7A = D7Dist_<D7, D7>(d7DeloneReduced_1, d7DeloneReduced_2);
m_rnPath.AddDistance(dist6);
m_rnPath.AddDeloneDistance(dist7);
m_rnPath.Add(vNext, TVEC(g6DeloneReduced_2));
}
else {
std::cout << "Reduce failed in Procession " << vNext << std::endl;
}
}
return(*this);
}
size_t size(void) const { return(m_rnPath.size()); };
bool empty(void) const { return(m_rnPath.empty()); }
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// Set the number of steps from the perturbed vector to the reduced one
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
Follow& SetStepCount(const size_t count) {
assert(count > 4);
this->m_steps = count;
return(*this);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
Follow& SetWhichComponentsToPlot(const int c1, const int c2) {
m_rnPath.SetWhichComponentsToPlot(c1, c2);
m_whichComponentsToPlot = std::make_pair(c1, c2);
return(*this);
}
const std::vector<triple<double, double, double> > GetLinesFromAngles(void) const { return(m_rnPath.GetAngleData()); };
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const std::list<double> GetDistances(void) const {
const std::list<double> distances(m_rnPath.GetDistances());
assert(!distances.empty());
return(distances);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const std::list<double> GetDeloneDistances(void) const {
const std::list<double> distances(m_rnPath.GetDeloneDistances());
assert(!distances.empty());
return(distances);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const std::pair< std::pair<double, double>, std::pair<double, double> > GetLimits(void)
/*-------------------------------------------------------------------------------------*/
{
return(m_rnPath.GetLimits());
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// Get the number of steps from the perturbed vector to the reduced one
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const double GetCirclePlotDiagonal(void) {
assert(!m_rnPath.empty());
return(m_rnPath.GetCirclePlotDiagonal());
}
const std::pair<int, int> GetWhichToPlot(void) const { return(m_whichComponentsToPlot); }
std::string GetBoundaryString(const size_t n) const {
if (typeid(TVEC) == typeid(G6))
return(m_rnPath.G6GetBoundaryString(n));
else if (typeid(TVEC) == typeid(D7))
return(m_rnPath.D7GetBoundaryString(n));
else
throw;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const std::vector<TVEC> GetProbeList(void) const {
return(m_rnPath.GetProbeList());
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const std::vector<TVEC> GetSecondProbeList(void) const {
return(m_rnPath.GetSecondProbeList());
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const double GetTime2ComputerFrame(void) const {
return(m_seconds2ComputerFrame);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const std::vector<Glitch<TVEC> > GetGlitches(void) const {
return(m_glitches);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
std::vector<Glitch<TVEC> > DetermineOutliers(const std::vector<double> distanceList, const std::pair<double, double>& minMaxDeltaDistance)
/*-------------------------------------------------------------------------------------*/
{
const size_t nDistances = distanceList.size();
const std::vector<Glitch<TVEC> > temp;
double prev = distanceList[0];
const double distmax = *std::max_element(distanceList.begin(), distanceList.end());
if (distmax > 0.3) {
const double distmin = *std::min_element(distanceList.begin(), distanceList.end());
const double range = distmax - distmin;
if (range <= 1.0E-10 || range < 0.01*minMaxDeltaDistance.second) return(temp);
for (size_t i = 1; i < nDistances; ++i) {
const double delta = std::abs(distanceList[i] - prev);
if (delta > 0.01*range && FollowerConstants::globalAboveThisValueIsBad < delta / (distanceList[i] + prev)) {
const std::vector<TVEC> probes(GetProbeList());
const GlitchElement<TVEC> Glitch1(distanceList[i], i, probes[i]);
const GlitchElement<TVEC> Glitch2(distanceList[i - size_t(1)], i - size_t(1), probes[i - size_t(1)]);
m_glitches.push_back(Glitch<TVEC>(Glitch1, Glitch2));
++i;
}
if (i < nDistances) prev = distanceList[i];
}
}
return(m_glitches);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// Essentially what is going on here is to identify the straight line segments and
// where the breaks are.
std::vector<long> IdentifyRunsOfAngle(const std::vector<triple<double, double, double> >& angles)
/*-------------------------------------------------------------------------------------*/
{
const size_t numAngles = angles.size();
std::vector<long> runs(1L, 1);
int runCount = 0;
const std::vector<long> newruns = AssignRunOrdinalToEachPoint(angles);
runs.insert(runs.end(), newruns.begin(), newruns.end());
std::vector<long> numberOfPointsInRun(numAngles + 1, 0);
// this is slow but easy to code
// For each run of same slope, store the number of points in that run.
for (size_t iangle = 1; iangle < numAngles; ++iangle)
++numberOfPointsInRun[runs[iangle]];
std::vector<long> countOfItemsInThisRun;
// Enumerate for each circle, how many total circles there are in its run.
// If there is only one, then we will need to draw a line and add labels.
for (size_t i = 0; i < angles.size(); ++i)
countOfItemsInThisRun.push_back(numberOfPointsInRun[runs[i]]);
return(countOfItemsInThisRun);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
std::vector<long> AssignRunOrdinalToEachPoint(const std::vector<triple<double, double, double> >& angles)
/*-------------------------------------------------------------------------------------*/
{
// For every point (except the first) store an ordinal of which run of slope
// each point has.
int runCount = 0;
std::vector<long> runs;
const size_t numAngles = angles.size();
for (size_t i = 1; i < numAngles; ++i) {
runCount += IncrementRunCount(angles[i].first, angles[i - 1].first);
runs.push_back(runCount);
}
return(runs);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
static const bool SameSlope(const double angle1, const double angle2) {
const double pi = 4.0 * std::atan(1.0);
const double anglediff = std::abs(angle1 - angle2); // RADIANS
const double angleDiffMin = minNC(anglediff, std::abs(anglediff - pi), std::abs(anglediff - 2.0*pi));
return angleDiffMin < 0.001;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const std::vector<Glitch<TVEC> > DetermineIfSomeDeltaIsTooLarge(const std::list<double>& distancesList)
/*-------------------------------------------------------------------------------------*/
{
const std::vector<double> distances(distancesList.begin(), distancesList.end());
const double maximumDistance = *std::max_element(distances.begin(), distances.end());
const std::pair<double, double> minmaxDeltaDistance = GetMinMaxDeltaDistances(distances);
std::vector<Glitch<TVEC> > glitches(DetermineOutliers(distances, minmaxDeltaDistance));
return(glitches);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
const std::vector<Glitch<TVEC> > DetermineIfSomeDeltaIsTooLarge(void) {
return(DetermineIfSomeDeltaIsTooLarge(this->GetDistances()));
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void SetTime2ComputeFrame(const double computeTime) {
m_seconds2ComputerFrame = computeTime;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
static std::pair<double, double> GetMinMaxDeltaDistances(const std::vector<double>& distances) {
double minDelta = DBL_MAX;
double maxDelta = -DBL_MAX;
std::vector<double>::const_iterator it = ++distances.begin();
double prev = *distances.begin();
for (; it != distances.end(); ++it) {
const double absDelta = std::abs((*it) - prev);
minDelta = std::min(minDelta, absDelta);
maxDelta = std::max(maxDelta, absDelta);
prev = *it;
}
return(std::make_pair(minDelta, maxDelta));
}
private:
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
int IncrementRunCount(const double& angle_I, const double& angle_IMinusOne) {
const double anglediff(SameSlope(angle_I, angle_IMinusOne) ? 0.0 : angle_I - angle_IMinusOne);
return((std::abs(anglediff) > 0.001) ? 1 : 0);
}
size_t m_steps;
Rn_Path<TVEC> m_rnPath;
std::pair<int, int> m_whichComponentsToPlot;
double m_seconds2ComputerFrame;
std::vector<Glitch<TVEC> > m_glitches;
};
#endif