00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#ifndef _GRSIMPLESCOPESINK_H_
00024
#define _GRSIMPLESCOPESINK_H_
00025
00026
#include <VrSink.h>
00027
#include "VrGUI.h"
00028
00029
00030
extern "C" {
00031
#include <dlfcn.h>
00032
#include <float.h>
00033
#include <math.h>
00034 }
00035
00036 #define XAXIS_NAME "Time"
00037 #define YAXIS_NAME "Amplitude"
00038
00039
00040
template<
class iType>
00041 class GrSimpleScopeSink :
public VrSink<iType> {
00042
00043
public:
00044 virtual const char *
name() {
return "GrSimpleScopeSink"; }
00045
00046
virtual int work3(
VrSampleRange output,
00047
VrSampleRange inputs[],
void *i[]);
00048
00049 void clear() {
plot->
clear(); }
00050 void set_persistent(
int arg_persistent) {
plot->
set_persistent(arg_persistent); }
00051
00052
GrSimpleScopeSink(
VrGUILayout *layout,
double arg_ymin,
double arg_ymax,
00053
int arg_nPoints = maxnPoints);
00054
~GrSimpleScopeSink();
00055
00056
00057 static const int maxnPoints = 1000;
00058 static const int divisions = 10;
00059
00060
private:
00061 double *
xValues;
00062 double *
yValues;
00063 int nPoints;
00064 int ncollected;
00065
00066 VrGUIPlot *
plot;
00067 double ymin,
ymax;
00068 };
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
template<
class iType>
00079 GrSimpleScopeSink<iType>::GrSimpleScopeSink(
VrGUILayout *layout,
00080
double arg_ymin,
double arg_ymax,
int arg_nPoints)
00081 {
00082
nPoints = arg_nPoints;
00083
if (
nPoints >
maxnPoints)
00084
nPoints =
maxnPoints;
00085
00086
ncollected = 0;
00087
00088
yValues =
new double[
nPoints];
00089
xValues =
new double[
nPoints];
00090
00091
for (
int i = 0; i <
nPoints; i++)
00092
xValues[i] = i;
00093
00094
ymin = arg_ymin;
00095
ymax = arg_ymax;
00096
00097
00098
plot =
new VrGUIPlot (layout,
XAXIS_NAME,
YAXIS_NAME, 1,
00099 0, nPoints, (
int)
ymin, (
int)
ymax, nPoints,
divisions);
00100
00101
00102 }
00103
00104
template<
class iType>
int
00105 GrSimpleScopeSink<iType>::work3(
VrSampleRange output,
00106
VrSampleRange inputs[],
void *ai[])
00107 {
00108
iType **i = (
iType **)ai;
00109
sync(output.
index);
00110
00111
unsigned int n;
00112
bool already_output_something_p =
false;
00113
00114
for (n = 0; n < output.
size; n++){
00115
yValues[
ncollected++] = *i[0]++;
00116
if (
ncollected ==
nPoints){
00117
if (!already_output_something_p){
00118
plot->
data (
xValues,
yValues,
nPoints);
00119 already_output_something_p =
true;
00120 }
00121
ncollected = 0;
00122 }
00123 }
00124
00125
return output.
size;
00126 }
00127
00128
template<
class iType>
00129 GrSimpleScopeSink<iType>::~GrSimpleScopeSink()
00130 {
00131
delete[]
xValues;
00132
delete[]
yValues;
00133
00134 }
00135
00136
#endif
00137
00138
00139