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

Last change on this file since 4173 was 3362, checked in by ldelgass, 12 years ago

Merge nanovis2 branch to trunk

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) 2004-2012  HUBzero Foundation, LLC
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";
20
21Array1D::Array1D()
22    : Object(),
23      _min(std::numeric_limits<double>::max()),
24      _max(std::numeric_limits<double>::min())
25{
26    name("");
27    label("");
28    desc("");
29    units("");
30    scale("linear");
31}
32
33Array1D::Array1D(const double *val, size_t size)
34    : Object(),
35      _min(std::numeric_limits<double>::max()),
36      _max(std::numeric_limits<double>::min())
37{
38    name("");
39    label("");
40    desc("");
41    units("");
42    scale("linear");
43    append(val,size);
44}
45
46// copy constructor
47Array1D::Array1D(const Array1D& o)
48    : _val(o._val),
49      _min(o._min),
50      _max(o._max)
51{
52    name(o.name());
53    label(o.label());
54    desc(o.desc());
55    units(o.units());
56    scale(o.scale());
57}
58
59// default destructor
60Array1D::~Array1D ()
61{
62    // clean up dynamic memory
63}
64
65/**********************************************************************/
66// METHOD: append()
67/// Append value to the axis
68/**
69 * Append value to the axis object.
70 */
71
72Array1D&
73Array1D::append(const double *val, size_t nmemb)
74{
75    double nmin = _min;
76    double nmax = _max;
77
78    for (size_t i = 0; i < nmemb; i++) {
79        if (val[i] < nmin) {
80            nmin = val[i];
81        }
82        if (val[i] > nmax) {
83            nmax = val[i];
84        }
85    }
86
87    _val.append(val,nmemb);
88
89    _min = nmin;
90    _max = nmax;
91
92    return *this;
93}
94
95/**********************************************************************/
96// METHOD: clear()
97/// clear data values from the object
98/**
99 * Clear data values from the object
100 */
101
102Array1D&
103Array1D::clear()
104{
105    _val.clear();
106    return *this;
107}
108
109/**********************************************************************/
110// METHOD: read()
111/// Read values from the axis object into a memory location
112/**
113 * Read values from the axis object into a memory location
114 */
115
116size_t
117Array1D::read(double *val, size_t nmemb)
118{
119    return _val.read(val,nmemb);
120}
121
122/**********************************************************************/
123// METHOD: nmemb()
124/// Return the number of members in the axis object
125/**
126 * Return the number of members in the axis object
127 */
128
129size_t
130Array1D::nmemb() const
131{
132    return _val.nmemb();
133}
134
135/**********************************************************************/
136// METHOD: min()
137/// Return the min value of the object
138/**
139 * Return the min value of the object
140 */
141
142double
143Array1D::min() const
144{
145    return _min;
146}
147
148/**********************************************************************/
149// METHOD: max()
150/// Return the max value of the object
151/**
152 * Return the max value of the object
153 */
154
155double
156Array1D::max() const
157{
158    return _max;
159}
160
161/**********************************************************************/
162// METHOD: data()
163/// Return the actual data pointer
164/**
165 * Return the actual data pointer
166 */
167
168const double *
169Array1D::data() const
170{
171    return _val.bytes();
172}
173
174/**********************************************************************/
175// METHOD: xml()
176/// Return the xml text representation of this object
177/**
178 * Return the xml text representation of this object
179 */
180
181const char *
182Array1D::xml(size_t indent, size_t tabstop)
183{
184    return "";
185}
186
187/**********************************************************************/
188// METHOD: xml()
189/// Return the xml text representation of this object
190/**
191 * Return the xml text representation of this object
192 */
193
194const int
195Array1D::is() const
196{
197    // return "ar1d" in hex
198    return 0x61723164;
199}
200
201// -------------------------------------------------------------------- //
202
Note: See TracBrowser for help on using the repository browser.