source: trunk/src/objects/RpArray1D.cc @ 1397

Last change on this file since 1397 was 1386, checked in by dkearney, 15 years ago

adding a few object prototypes we can play with for future developement. the plot object is probably the most interesting. examples are located in examples/objects dirs

File size: 4.0 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  Rappture 2.0 Array1D Object Source
4 *
5 * ======================================================================
6 *  AUTHOR:  Derrick Kearney, Purdue University
7 *  Copyright (c) 2005-2009  Purdue Research Foundation
8 *
9 *  See the file "license.terms" for information on usage and
10 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * ======================================================================
12 */
13
14#include <limits>
15#include "RpArray1D.h"
16
17using namespace Rappture;
18
19const char Array1D::type[]        = "RAPPTURE_AXIS_TYPE_IRREGULAR";
20const char Array1DUniform::type[] = "RAPPTURE_AXIS_TYPE_UNIFORM";
21
22Array1D::Array1D (const char *path)
23    : _val(SimpleDoubleBuffer()),
24      _min(std::numeric_limits<double>::max()),
25      _max(std::numeric_limits<double>::min())
26{
27    this->path(path);
28    this->label("");
29    this->desc("");
30    this->units("");
31    this->scale("linear");
32}
33
34Array1D::Array1D (
35            const char *path,
36            double *val,
37            size_t size
38        )
39    : _val(SimpleDoubleBuffer()),
40      _min(std::numeric_limits<double>::max()),
41      _max(std::numeric_limits<double>::min())
42{
43    this->path(path);
44    this->label("");
45    this->desc("");
46    this->units("");
47    this->scale("linear");
48    append(val,size);
49}
50
51Array1D::Array1D (
52            const char *path,
53            double *val,
54            size_t size,
55            const char *label,
56            const char *desc,
57            const char *units,
58            const char *scale
59        )
60    : _val(SimpleDoubleBuffer()),
61      _min(std::numeric_limits<double>::max()),
62      _max(std::numeric_limits<double>::min())
63{
64    this->path(path);
65    this->label(label);
66    this->desc(desc);
67    this->units(units);
68    this->scale(scale);
69    append(val,size);
70}
71
72// copy constructor
73Array1D::Array1D ( const Array1D& o )
74    : _val(o._val),
75      _min(o._min),
76      _max(o._max)
77{
78    this->path(o.path());
79    this->label(o.label());
80    this->desc(o.desc());
81    this->units(o.units());
82    this->scale(o.scale());
83}
84
85// default destructor
86Array1D::~Array1D ()
87{
88    // clean up dynamic memory
89}
90
91/**********************************************************************/
92// METHOD: append()
93/// Append value to the axis
94/**
95 * Append value to the axis object.
96 */
97
98Array1D&
99Array1D::append(
100    double *val,
101    size_t nmemb)
102{
103    double nmin = _min;
104    double nmax = _max;
105
106    for (size_t i = 0; i < nmemb; i++) {
107        if (val[i] < nmin) {
108            nmin = val[i];
109        }
110        if (val[i] > nmax) {
111            nmax = val[i];
112        }
113    }
114
115    _val.append(val,nmemb);
116
117    _min = nmin;
118    _max = nmax;
119
120    return *this;
121}
122
123/**********************************************************************/
124// METHOD: read()
125/// Read values from the axis object into a memory location
126/**
127 * Read values from the axis object into a memory location
128 */
129
130size_t
131Array1D::read(
132    double *val,
133    size_t nmemb)
134{
135    return _val.read(val,nmemb);
136}
137
138/**********************************************************************/
139// METHOD: nmemb()
140/// Return the number of members in the axis object
141/**
142 * Return the number of members in the axis object
143 */
144
145size_t
146Array1D::nmemb() const
147{
148    return _val.nmemb();
149}
150
151/**********************************************************************/
152// METHOD: min()
153/// Return the min value of the object
154/**
155 * Return the min value of the object
156 */
157
158double
159Array1D::min() const
160{
161    return _min;
162}
163
164/**********************************************************************/
165// METHOD: max()
166/// Return the max value of the object
167/**
168 * Return the max value of the object
169 */
170
171double
172Array1D::max() const
173{
174    return _max;
175}
176
177/**********************************************************************/
178// METHOD: data()
179/// Return the actual data pointer
180/**
181 * Return the actual data pointer
182 */
183
184const double *
185Array1D::data() const
186{
187    return _val.bytes();
188}
189
190// -------------------------------------------------------------------- //
191
Note: See TracBrowser for help on using the repository browser.