-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPulseManager.cpp
More file actions
183 lines (169 loc) · 5.91 KB
/
PulseManager.cpp
File metadata and controls
183 lines (169 loc) · 5.91 KB
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
#include "PulseManager.h"
#include <string.h>
#include <gmtl/gmtl.h>
//-----------------------------------------------------------------------------
PulseManager::PulseManager(
const Types::Public_Header_Block &i_publicHeader,
const Types::WF_packet_Descriptor &i_wv_info
):
m_noiseLevel(30.0)
{
memcpy((void*) &m_public_header,(void*)&i_publicHeader,sizeof(m_public_header));
memcpy((void*) &m_wfInfo,(void *) &i_wv_info, sizeof(m_wfInfo));
}
//-----------------------------------------------------------------------------
PulseManager::PulseManager(
const PulseManager &i_pulseManager
)
{
memcpy((void*) &m_public_header,(void*)&i_pulseManager.m_public_header,
sizeof(m_public_header));
memcpy((void*) &m_wfInfo,(void *) &i_pulseManager.m_wfInfo,
sizeof(m_wfInfo));
m_pulses.resize(i_pulseManager.m_pulses.size());
for(unsigned int i=0; i<m_pulses.size(); ++i)
{
m_pulses[i] = new Pulse(*i_pulseManager.m_pulses[i]);
}
}
//-----------------------------------------------------------------------------
void PulseManager::setNoiseLevel(double i_noiseLevel)
{
m_noiseLevel = i_noiseLevel;
}
//-----------------------------------------------------------------------------
void PulseManager::printPulseInfo(unsigned int i_pulse)
{
if(i_pulse<m_pulses.size())
{
m_pulses[i_pulse]->print();
}
else
{
std::cout << "Pulse with index " << i_pulse << " doesn't exist\n";
}
}
//-----------------------------------------------------------------------------
void PulseManager::addPoint(
const Types::Data_Point_Record_Format_4 &i_point,
const unsigned char *wave_data,
int wave_offset
)
{
float originZ = i_point.Z*m_public_header.z_scale_factor +
(float)i_point.Z_t*i_point.return_point_wf_location;
if(originZ < 110.f)
{
Pulse *pulse = new Pulse(m_public_header,m_wfInfo,i_point,wave_data,wave_offset);
m_pulses.push_back(pulse);
const gmtl::Vec3f &origin = m_pulses[m_pulses.size()-1]->getOrigin();
const gmtl::Vec3f &offset = m_pulses[m_pulses.size()-1]->getOffset();
gmtl::Vec3f endPoint(offset);
endPoint*=(m_wfInfo.number_of_samples);
endPoint+=origin;
m_public_header.max_x = std::max((double)origin[0],m_public_header.max_x);
m_public_header.max_x = std::max((double)endPoint[0],m_public_header.max_x);
m_public_header.max_y = std::max((double)origin[1],m_public_header.max_y);
m_public_header.max_y = std::max((double)endPoint[1],m_public_header.max_y);
m_public_header.max_z = std::max((double)origin[2],m_public_header.max_z);
m_public_header.max_z = std::max((double)endPoint[2],m_public_header.max_z);
std::pair<int,unsigned int> pair(wave_offset,m_pulses.size()-1);
myMap.insert(pair);
}
}
//-----------------------------------------------------------------------------
void PulseManager::sortDiscretePoints(
const std::vector<gmtl::Vec3f> &m_discretePoints,
const std::vector<unsigned short> &m_discreteIntensities,
const std::vector<int> &m_discreteWaveOffsets
)
{
for(unsigned int i=0; i<m_discreteIntensities.size(); ++i)
{
std::unordered_map<int,unsigned int>::const_iterator got =
myMap.find(m_discreteWaveOffsets[i]);
if(got == myMap.end())
{
}
else
{
m_pulses[got->second]->addDiscretePoint(m_discretePoints[i],m_discreteIntensities[i]);
}
}
}
//-----------------------------------------------------------------------------
void PulseManager::addUnAssociatedDiscretePoint(
const Types::Data_Point_Record_Format_4 &i_point_info
)
{
m_discretePoints.push_back(
gmtl::Vec3f(i_point_info.X*m_public_header.x_scale_factor,
i_point_info.Y*m_public_header.y_scale_factor,
i_point_info.Z*m_public_header.z_scale_factor));
m_discreteIntensities.push_back(i_point_info.itensity);
}
//-----------------------------------------------------------------------------
void PulseManager::sortPulseWithRespectToY()
{
// array to be sorted
unsigned int len = m_pulses.size();
// allocate memory for temporarly saved values
std::vector<Pulse *> tempValues;
tempValues.resize(len);
// start sorting 2 elements each time, then merge them with the two next to them etc
for(unsigned int step=2; step/2 < len; step*=2)
{
for(unsigned int i=0; i < len; i+=step)
{
unsigned int endOfT2 = i+step;
if(i+ step/2 >= len)
{
continue;
}
else if (i+step >=len)
{
endOfT2 = len;
}
// both sets have step/2 items.
// t1 points to the first set of values
unsigned int t1 = i;
// t2 points to the second set of values
unsigned int t2 = i+step/2;
// here we save all the values that have been overridden from the first set
unsigned int tempIndex=0;
while(t1 < i+step/2 && t2 < endOfT2)
{
if(m_pulses[t1]->m_origin[1]>m_pulses[t2]->m_origin[1])
{
tempValues[tempIndex]=m_pulses[t1];
t1++;
}
else
{
tempValues[tempIndex]=m_pulses[t2];
t2++;
}
tempIndex++;
}
while(t1<i+step/2)
{
tempValues[tempIndex]=m_pulses[t1];
t1++;
tempIndex++;
}
// write values back to the array
for(unsigned int t=0; t < tempIndex; ++t)
{
m_pulses[i+t]=tempValues[t];
}
}
}
}
//-----------------------------------------------------------------------------
PulseManager::~PulseManager()
{
for(unsigned int i=0; i<m_pulses.size(); ++i)
{
delete m_pulses[i];
}
}