source: trunk/src/core2/RpFieldPrism3D.cc @ 1030

Last change on this file since 1030 was 657, checked in by dkearney, 17 years ago

cleaned up all the compile time warnings in core rappture2 objects

File size: 3.4 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  Rappture::FieldPrism3D
4 *    This is a continuous, linear function defined by a series of
5 *    points on a 3D prismatic mesh.  It's a scalar field defined
6 *    in 3D space.
7 *
8 * ======================================================================
9 *  AUTHOR:  Michael McLennan, Purdue University
10 *  Copyright (c) 2004-2006  Purdue Research Foundation
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16#include "RpFieldPrism3D.h"
17
18using namespace Rappture;
19
20FieldPrism3D::FieldPrism3D()
21  : _valuelist(),
22    _meshPtr(NULL),
23    _counter(0)
24{
25}
26
27FieldPrism3D::FieldPrism3D(const MeshTri2D& xyg, const Mesh1D& zg)
28  : _valuelist(),
29    _meshPtr(NULL),
30    _counter(0)
31{
32    _meshPtr = Ptr<MeshPrism3D>( new MeshPrism3D(xyg,zg) );
33    int npts = xyg.sizeNodes()*zg.size();
34    _valuelist.reserve(npts);
35}
36
37FieldPrism3D::FieldPrism3D(const FieldPrism3D& field)
38  : _valuelist(field._valuelist),
39    _meshPtr(field._meshPtr),
40    _counter(field._counter)
41{
42}
43
44FieldPrism3D&
45FieldPrism3D::operator=(const FieldPrism3D& field)
46{
47    _valuelist = field._valuelist;
48    _meshPtr = field._meshPtr;
49    _counter = field._counter;
50    return *this;
51}
52
53FieldPrism3D::~FieldPrism3D()
54{
55}
56
57double
58FieldPrism3D::rangeMin(Axis which) const
59{
60    if (!_meshPtr.isNull()) {
61        return _meshPtr->rangeMin(which);
62    }
63    return 0.0;
64}
65
66double
67FieldPrism3D::rangeMax(Axis which) const
68{
69    if (!_meshPtr.isNull()) {
70        return _meshPtr->rangeMax(which);
71    }
72    return 0.0;
73}
74
75FieldPrism3D&
76FieldPrism3D::define(int nodeId, double f)
77{
78    while (_valuelist.size() <= (unsigned int)nodeId) {
79        _valuelist.push_back(NAN);
80    }
81    _valuelist[nodeId] = f;
82
83    if (isnan(_vmin) || isnan(_vmax)) {
84        _vmin = _vmax = f;
85    } else {
86        if (f < _vmin) { _vmin = f; }
87        if (f > _vmax) { _vmax = f; }
88    }
89    return *this;
90}
91
92double
93FieldPrism3D::value(double x, double y, double z, double outside) const
94{
95    if (!_meshPtr.isNull()) {
96        CellPrism3D cell = _meshPtr->locate(Node3D(x,y,z));
97
98        // outside the defined data? then return the outside value
99        if (cell.isOutside()) {
100            return outside;
101        }
102
103        // interpolate first xy triangle
104        double fz0, fz1, phi[3];
105
106        Node2D node( x, y );
107        Node2D n1( cell.x(0), cell.y(0) );
108        Node2D n2( cell.x(1), cell.y(1) );
109        Node2D n3( cell.x(2), cell.y(2) );
110
111        CellTri2D tri(0, &n1, &n2, &n3);
112        tri.barycentrics(node, phi);
113
114        fz0 = phi[0]*_valuelist[ cell.nodeId(0) ]
115            + phi[1]*_valuelist[ cell.nodeId(1) ]
116            + phi[2]*_valuelist[ cell.nodeId(2) ];
117
118        // interpolate second xy triangle
119        fz1 = phi[0]*_valuelist[ cell.nodeId(3) ]
120            + phi[1]*_valuelist[ cell.nodeId(4) ]
121            + phi[2]*_valuelist[ cell.nodeId(5) ];
122
123        double zrange = cell.z(5) - cell.z(0);
124
125        if (zrange == 0.0) {
126            // interval undefined? then return avg value
127            return 0.5*(fz1+fz0);
128        }
129        // interpolate along z-axis
130        double delz = z - cell.z(0);
131        return fz0 + (delz/zrange)*(fz1-fz0);
132    }
133    return outside;
134}
135
136double
137FieldPrism3D::valueMin() const
138{
139    return _vmin;
140}
141
142double
143FieldPrism3D::valueMax() const
144{
145    return _vmax;
146}
Note: See TracBrowser for help on using the repository browser.