-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineDisplayHandler2D.cpp
More file actions
185 lines (145 loc) · 6.04 KB
/
Copy pathLineDisplayHandler2D.cpp
File metadata and controls
185 lines (145 loc) · 6.04 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
184
185
/*
* Copyright (c) 2010-2016 Stephane Poirier
*
* stephane.poirier@oifii.org
*
* Stephane Poirier
* 3532 rue Ste-Famille, #3
* Montreal, QC, H2X 2L1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "LineDisplayHandler2D.h"
//Constructor
LineDisplayHandler2D :: LineDisplayHandler2D(float displayMinXIn, float displayWidthXIn, float displayMinYIn, float displayHeightYIn, SAMPLE minDataXValueDisplayedIn, SAMPLE maxDataXValueDisplayedIn, SAMPLE dataYValueLimitLowIn, SAMPLE dataYValueLimitHighIn, bool dataXUpdatingIn, bool dataYUpdatingIn, long lengthOfDataBuffersIn, const SAMPLE* dataXValuesIn, const SAMPLE* dataYValuesIn)
{
//Assert that display dimensions have non-zero, positive width, except in dimensions which will not be plotted
assert( displayWidthXIn > 0.0);
assert( displayHeightYIn > 0.0);
assert( lengthOfDataBuffersIn > 0 );
displayMinX = displayMinXIn;
displayWidthX = displayWidthXIn;
displayMinY = displayMinYIn;
displayHeightY = displayHeightYIn;
dataYValueLimitLow = dataYValueLimitLowIn;
dataYValueLimitHigh = dataYValueLimitHighIn;
minDataXValueDisplayed = minDataXValueDisplayedIn;
maxDataXValueDisplayed = maxDataXValueDisplayedIn;
lengthOfDataBuffers = lengthOfDataBuffersIn;
dataXValues = dataXValuesIn;
dataYValues = dataYValuesIn;
dataXUpdating = dataXUpdatingIn;
dataYUpdating = dataYUpdatingIn;
displayXValues = new float[lengthOfDataBuffers];
displayYValues = new float[lengthOfDataBuffers];
//Should really be calculated based on min and max X values to be displayed and the values in the dataXValues array.
//Currently just defaults to no zoom (plus we currently have no way of changing this since the fns arent implemented)
currentPlotLength = lengthOfDataBuffers;
//Initialization really needs for all of data providing structure to be ready first.
//May need to reorganize this interaction...
// NEED TO INIALIZE DATA ARRAY IN DERIVED CLASS FIRST
/*
//If any dimension has been flagged as not updating, generate the display values array for that dimension. This will remain static until the display parameters are changed, and only recalculated then.
if( !dataXUpdating )
makeStaticDisplayArray( 0 );
if( !dataYUpdating )
makeStaticDisplayArray( 1 );
*/
}
//Destructor
LineDisplayHandler2D :: ~LineDisplayHandler2D()
{
delete []displayXValues;
delete []displayYValues;
}
// Change lengthOfDataBuffers - resets object displayValues
void LineDisplayHandler2D :: changeLengthOfDataBuffers( long lengthOfDataBuffersIn )
{
assert( lengthOfDataBuffersIn > 0 );
lengthOfDataBuffers = lengthOfDataBuffersIn;
delete []displayXValues;
delete []displayYValues;
displayXValues = new float[lengthOfDataBuffers];
displayYValues = new float[lengthOfDataBuffers];
//Remake static buffers
if( !dataXUpdating )
makeStaticDisplayArray( 0 );
if( !dataYUpdating )
makeStaticDisplayArray( 1 );
//Note: refreshDisplayValues still needs to be called before displaying. This should be done in any display loop anyways though.
}
//Recalculates the values in the displayValues arrays based on the data in the dataValues arrays except for dimensions with data_Updating = flase.
void LineDisplayHandler2D :: refreshDisplayValues()
{
//Only refresh those dimensions which have data that is updating
if( dataXUpdating )
{
//Calculate the range of values X takes.
float deltaXVal = dataXValues[lengthOfDataBuffers-1] - dataXValues[0];
for( int i = 0; i < lengthOfDataBuffers; i++ )
displayXValues[i] = displayMinX + ( (dataXValues[i] - dataXValues[0]) / deltaXVal ) * displayWidthX;
}
if( dataYUpdating )
{
for( int i = 0; i < lengthOfDataBuffers; i++ )
{
if( dataYValues[i] < dataYValueLimitLow )
displayYValues[i] = displayMinY;
else if( dataYValues[i] > dataYValueLimitHigh )
displayYValues[i] = displayMinY + displayHeightY;
else
displayYValues[i] = displayMinY + ( (dataYValues[i] - dataYValueLimitLow) / (dataYValueLimitHigh - dataYValueLimitLow) ) * displayHeightY;
}
}
}
//Calculates display arrays which do not need to be updated during each call to refreshDisplay().
void LineDisplayHandler2D :: makeStaticDisplayArray(int arrayNumber)
{
if( arrayNumber == 0 ) // X dimension array. Assumes dataXValues is ordered low to high in values.
{
if( dataXValues == NULL )
std::cout << "Trying to makeStaticDisplayArray for NULL X data pointer!! Nothing will be done." << std::endl;
else
{
//Calculate the range of values X takes.
float deltaXVal = (float)(dataXValues[lengthOfDataBuffers-1] - dataXValues[0]);
for( int i = 0; i < lengthOfDataBuffers; i++ )
displayXValues[i] = displayMinX + ( (dataXValues[i] - dataXValues[0]) / deltaXVal ) * displayWidthX;
}
}
else if( arrayNumber == 1 ) // Y dimension array. NOT Assumed to be ordered.
{
if( dataYValues == NULL )
std::cout << "Trying to makeStaticDisplayArray for NULL Y data pointer!! Nothing will be done." << std::endl;
else
{
for( int i = 0; i < lengthOfDataBuffers; i++ )
{
if( dataYValues[i] < dataYValueLimitLow )
displayYValues[i] = displayMinY;
else if( dataYValues[i] > dataYValueLimitHigh )
displayYValues[i] = displayMinY + displayHeightY;
else
displayYValues[i] = displayMinY + (dataYValues[i] - dataYValueLimitLow) * displayHeightY;
}
}
}
}
void LineDisplayHandler2D :: setMinDataXValueDisplayed(SAMPLE minDataXValueDisplayedIn)
{
}
void LineDisplayHandler2D :: setMaxDataXValueDisplayed(SAMPLE maxDataXValueDisplayedIn)
{
}