SamplePointList.cs
4.9 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
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections;
using System.Text;
namespace ZedGraph
{
/// <summary>
/// enumeration used to indicate which type of data will be plotted.
/// </summary>
public enum SampleType
{
/// <summary>
/// Designates the "Time" property will be used
/// </summary>
Time,
/// <summary>
/// Designates the "Position" property will be used
/// </summary>
Position,
/// <summary>
/// Designates the Instantaneous Velocity property will be used
/// </summary>
VelocityInst,
/// <summary>
/// Designates the "Time since start" property will be used
/// </summary>
TimeDiff,
/// <summary>
/// Designates the Average Velocity property will be used
/// </summary>
VelocityAvg
};
/// <summary>
/// A simple storage class to maintain an individual sampling of data
/// </summary>
public class Sample : System.Object
{
private DateTime _time;
private double _position;
private double _velocity;
/// <summary>
/// The time of the sample
/// </summary>
public DateTime Time
{
get { return _time; }
set { _time = value; }
}
/// <summary>
/// The position at sample time
/// </summary>
public double Position
{
get { return _position; }
set { _position = value; }
}
/// <summary>
/// The instantaneous velocity at sample time
/// </summary>
public double Velocity
{
get { return _velocity; }
set { _velocity = value; }
}
}
/// <summary>
/// A collection class to maintain a set of samples
/// </summary>
[Serializable]
public class SamplePointList : IPointList
{
/// <summary>
/// Determines what data type gets plotted for the X values
/// </summary>
public SampleType XType;
/// <summary>
/// Determines what data type gets plotted for the Y values
/// </summary>
public SampleType YType;
// Stores the collection of samples
private ArrayList list;
/// <summary>
/// Indexer: get the Sample instance at the specified ordinal position in the list
/// </summary>
/// <param name="index">The ordinal position in the list of samples</param>
/// <returns>Returns a <see cref="PointPair" /> instance containing the
/// data specified by <see cref="XType" /> and <see cref="YType" />
/// </returns>
public PointPair this[int index]
{
get
{
PointPair pt = new PointPair();
Sample sample = (Sample) list[index];
pt.X = GetValue( sample, XType );
pt.Y = GetValue( sample, YType );
return pt;
}
}
/// <summary>
/// Gets the number of samples in the collection
/// </summary>
public int Count
{
get { return list.Count; }
}
/// <summary>
/// Get the specified data type from the specified sample
/// </summary>
/// <param name="sample">The sample instance of interest</param>
/// <param name="type">The data type to be extracted from the sample</param>
/// <returns>A double value representing the requested data</returns>
public double GetValue( Sample sample, SampleType type )
{
switch ( type )
{
case SampleType.Position:
return sample.Position;
case SampleType.Time:
return sample.Time.ToOADate();
case SampleType.TimeDiff:
return sample.Time.ToOADate() - ( (Sample)list[0] ).Time.ToOADate();
case SampleType.VelocityAvg:
double timeDiff = sample.Time.ToOADate() - ( (Sample)list[0] ).Time.ToOADate();
if ( timeDiff <= 0 )
return PointPair.Missing;
else
return ( sample.Position - ( (Sample)list[0] ).Position ) / timeDiff;
case SampleType.VelocityInst:
return sample.Velocity;
default:
return PointPair.Missing;
}
}
/// <summary>
/// Append a sample to the collection
/// </summary>
/// <param name="sample">The sample to append</param>
/// <returns>The ordinal position at which the sample was added</returns>
public int Add( Sample sample )
{
return list.Add( sample );
}
// generic Clone: just call the typesafe version
object ICloneable.Clone()
{
return this.Clone();
}
/// <summary>
/// typesafe clone method
/// </summary>
/// <returns>A new cloned SamplePointList. This returns a copy of the structure,
/// but it does not duplicate the data (it just keeps a reference to the original)
/// </returns>
public SamplePointList Clone()
{
return new SamplePointList( this );
}
/// <summary>
/// default constructor
/// </summary>
public SamplePointList()
{
XType = SampleType.Time;
YType = SampleType.Position;
list = new ArrayList();
}
/// <summary>
/// copy constructor -- this returns a copy of the structure,
/// but it does not duplicate the data (it just keeps a reference to the original)
/// </summary>
/// <param name="rhs">The SamplePointList to be copied</param>
public SamplePointList( SamplePointList rhs )
{
XType = rhs.XType;
YType = rhs.YType;
// Don't duplicate the data values, just copy the reference to the ArrayList
this.list = rhs.list;
//foreach ( Sample sample in rhs )
// list.Add( sample );
}
}
}