source: branches/nanovis2/src/objects/RpArray1DUniform.cc @ 3305

Last change on this file since 3305 was 3305, checked in by ldelgass, 11 years ago

sync with trunk

File size: 3.1 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  Rappture 2.0 Array1DUniform 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 <cmath>
16#include "RpArray1DUniform.h"
17
18using namespace Rappture;
19
20const char Array1DUniform::type[] = "RAPPTURE_AXIS_TYPE_UNIFORM";
21
22Array1DUniform::Array1DUniform()
23    : Array1D(),
24      _step(0)
25{}
26
27Array1DUniform::Array1DUniform(double min, double max, double step)
28    : Array1D(),
29      _step(step)
30{
31    this->min(min);
32    this->max(max);
33    __fillBuffer();
34}
35
36Array1DUniform::Array1DUniform(double min, double max, size_t nmemb)
37    : Array1D(),
38      _step(0)
39{
40    this->min(min);
41    this->max(max);
42    this->step(__calcStepFromNmemb(nmemb));
43    __fillBuffer();
44}
45
46// copy constructor
47Array1DUniform::Array1DUniform ( const Array1DUniform& o )
48    : Array1D(o),
49      _step(o._step)
50{}
51
52// default destructor
53Array1DUniform::~Array1DUniform ()
54{
55    // clean up dynamic memory
56}
57
58/**********************************************************************/
59// METHOD: min()
60/// Set the min value and refill buffer
61/**
62 * Set the min value and refill buffer
63 */
64
65void
66Array1DUniform::min(double min)
67{
68    _min = min;
69    clear();
70    __fillBuffer();
71    return;
72}
73
74/**********************************************************************/
75// METHOD: max()
76/// Set the max value and refill buffer
77/**
78 * Set the max value and refill buffer
79 */
80
81void
82Array1DUniform::max(double max)
83{
84    _max = max;
85    clear();
86    __fillBuffer();
87    return;
88}
89
90/**********************************************************************/
91// METHOD: step()
92/// Get the step value
93/**
94 * Get the step value
95 */
96
97double
98Array1DUniform::step(void) const
99{
100    return _step;
101}
102
103/**********************************************************************/
104// METHOD: step()
105/// Set the step value and refill buffer
106/**
107 * Set the step value and refill buffer
108 */
109
110void
111Array1DUniform::step(double step)
112{
113    _step = step;
114    clear();
115    __fillBuffer();
116    return;
117}
118
119double
120Array1DUniform::__calcStepFromNmemb(size_t nmemb)
121{
122    double newstep = 0.0;
123
124    if (nmemb != 0) {
125        newstep = (Array1D::max()-Array1D::min()+1)/nmemb;
126    }
127
128    return newstep;
129}
130
131size_t
132Array1DUniform::__calcNmembFromStep(double step)
133{
134    size_t nmemb = 0;
135
136    if (step != 0) {
137        nmemb = (size_t) round((Array1D::max()-Array1D::min()+1)/step);
138    }
139
140    return nmemb;
141}
142
143void
144Array1DUniform::__fillBuffer()
145{
146    size_t bufSize = 0;
147
148    if (_step == 0) {
149        return;
150    }
151
152    bufSize = __calcNmembFromStep(_step);
153    _val.set(bufSize);
154
155    for(double i=_min; i <= _max; i=i+_step) {
156        _val.append(&i,1);
157    }
158
159    return;
160}
161
162// -------------------------------------------------------------------- //
163
Note: See TracBrowser for help on using the repository browser.