1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * Rappture::MeshRect3D |
---|
4 | * This is a non-uniform, structured 3D mesh. Each of the x, y, |
---|
5 | * and z-axes can be configured independently. Their product |
---|
6 | * forms a rectangular mesh 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 "RpMeshRect3D.h" |
---|
17 | |
---|
18 | using namespace Rappture; |
---|
19 | |
---|
20 | CellRect3D::CellRect3D() |
---|
21 | { |
---|
22 | for (int i=0; i < 8; i++) { |
---|
23 | _nodeIds[i] = -1; |
---|
24 | _x[i] = 0.0; |
---|
25 | _y[i] = 0.0; |
---|
26 | _z[i] = 0.0; |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | CellRect3D::CellRect3D(const CellRect3D& cell) |
---|
31 | { |
---|
32 | for (int i=0; i < 8; i++) { |
---|
33 | _nodeIds[i] = cell._nodeIds[i]; |
---|
34 | _x[i] = cell._x[i]; |
---|
35 | _y[i] = cell._y[i]; |
---|
36 | _z[i] = cell._z[i]; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | CellRect3D& |
---|
41 | CellRect3D::operator=(const CellRect3D& cell) |
---|
42 | { |
---|
43 | for (int i=0; i < 8; i++) { |
---|
44 | _nodeIds[i] = cell._nodeIds[i]; |
---|
45 | _x[i] = cell._x[i]; |
---|
46 | _y[i] = cell._y[i]; |
---|
47 | _z[i] = cell._z[i]; |
---|
48 | } |
---|
49 | return *this; |
---|
50 | } |
---|
51 | |
---|
52 | int& |
---|
53 | CellRect3D::nodeId(int n) |
---|
54 | { |
---|
55 | assert(n >= 0 && n < 8); |
---|
56 | return _nodeIds[n]; |
---|
57 | } |
---|
58 | |
---|
59 | double& |
---|
60 | CellRect3D::x(int n) |
---|
61 | { |
---|
62 | assert(n >= 0 && n < 8); |
---|
63 | return _x[n]; |
---|
64 | } |
---|
65 | |
---|
66 | double& |
---|
67 | CellRect3D::y(int n) |
---|
68 | { |
---|
69 | assert(n >= 0 && n < 8); |
---|
70 | return _y[n]; |
---|
71 | } |
---|
72 | |
---|
73 | double& |
---|
74 | CellRect3D::z(int n) |
---|
75 | { |
---|
76 | assert(n >= 0 && n < 8); |
---|
77 | return _z[n]; |
---|
78 | } |
---|
79 | |
---|
80 | int |
---|
81 | CellRect3D::isOutside() const |
---|
82 | { |
---|
83 | for (int i=0; i < 8; i++) { |
---|
84 | if (_nodeIds[i] < 0) { |
---|
85 | return 1; |
---|
86 | } |
---|
87 | } |
---|
88 | return 0; |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | MeshRect3D::MeshRect3D() |
---|
93 | { |
---|
94 | } |
---|
95 | |
---|
96 | MeshRect3D::MeshRect3D(const Mesh1D& xm, const Mesh1D& ym, const Mesh1D& zm) |
---|
97 | { |
---|
98 | _axis[0] = xm; |
---|
99 | _axis[1] = ym; |
---|
100 | _axis[2] = zm; |
---|
101 | } |
---|
102 | |
---|
103 | MeshRect3D::MeshRect3D(const MeshRect3D& mesh) |
---|
104 | : _axis(mesh._axis) |
---|
105 | { |
---|
106 | } |
---|
107 | |
---|
108 | MeshRect3D& |
---|
109 | MeshRect3D::operator=(const MeshRect3D& mesh) |
---|
110 | { |
---|
111 | _axis[0] = mesh._axis[0]; |
---|
112 | _axis[1] = mesh._axis[1]; |
---|
113 | _axis[2] = mesh._axis[2]; |
---|
114 | return *this; |
---|
115 | } |
---|
116 | |
---|
117 | MeshRect3D::~MeshRect3D() |
---|
118 | { |
---|
119 | } |
---|
120 | |
---|
121 | Node1D& |
---|
122 | MeshRect3D::add(Axis which, const Node1D& node) |
---|
123 | { |
---|
124 | return _axis[which].add(node); |
---|
125 | } |
---|
126 | |
---|
127 | MeshRect3D& |
---|
128 | MeshRect3D::remove(Axis which, int nodeId) |
---|
129 | { |
---|
130 | _axis[which].remove(nodeId); |
---|
131 | return *this; |
---|
132 | } |
---|
133 | |
---|
134 | MeshRect3D& |
---|
135 | MeshRect3D::remove(Axis which, const Node1D& node) |
---|
136 | { |
---|
137 | _axis[which].remove(node); |
---|
138 | return *this; |
---|
139 | } |
---|
140 | |
---|
141 | MeshRect3D& |
---|
142 | MeshRect3D::clear() |
---|
143 | { |
---|
144 | _axis[0].clear(); |
---|
145 | _axis[1].clear(); |
---|
146 | _axis[2].clear(); |
---|
147 | return *this; |
---|
148 | } |
---|
149 | |
---|
150 | int |
---|
151 | MeshRect3D::size(Axis which) const |
---|
152 | { |
---|
153 | return _axis[which].size(); |
---|
154 | } |
---|
155 | |
---|
156 | Node1D& |
---|
157 | MeshRect3D::at(Axis which, int pos) |
---|
158 | { |
---|
159 | return _axis[which].at(pos); |
---|
160 | } |
---|
161 | |
---|
162 | double |
---|
163 | MeshRect3D::rangeMin(Axis which) const |
---|
164 | { |
---|
165 | return _axis[which].rangeMin(); |
---|
166 | } |
---|
167 | |
---|
168 | double |
---|
169 | MeshRect3D::rangeMax(Axis which) const |
---|
170 | { |
---|
171 | return _axis[which].rangeMax(); |
---|
172 | } |
---|
173 | |
---|
174 | CellRect3D |
---|
175 | MeshRect3D::locate(const Node3D& node) const |
---|
176 | { |
---|
177 | CellRect3D result; |
---|
178 | Cell1D cells[3]; |
---|
179 | Node1D coord(0.0); |
---|
180 | |
---|
181 | coord.x(node.x()); |
---|
182 | cells[0] = _axis[0].locate(coord); |
---|
183 | |
---|
184 | coord.x(node.y()); |
---|
185 | cells[1] = _axis[1].locate(coord); |
---|
186 | |
---|
187 | coord.x(node.z()); |
---|
188 | cells[2] = _axis[2].locate(coord); |
---|
189 | |
---|
190 | int n = 0; |
---|
191 | for (int iz=0; iz < 2; iz++) { |
---|
192 | for (int iy=0; iy < 2; iy++) { |
---|
193 | for (int ix=0; ix < 2; ix++) { |
---|
194 | int nx = cells[0].nodeId(ix); |
---|
195 | int ny = cells[1].nodeId(iy); |
---|
196 | int nz = cells[2].nodeId(iz); |
---|
197 | if (nx >= 0 && ny >= 0 && nz >= 0) { |
---|
198 | result.nodeId(n) = nz*(_axis[0].size()*_axis[1].size()) |
---|
199 | + ny*(_axis[0].size()) |
---|
200 | + nx; |
---|
201 | result.x(n) = cells[0].x(ix); |
---|
202 | result.y(n) = cells[1].x(iy); |
---|
203 | result.z(n) = cells[2].x(iz); |
---|
204 | } |
---|
205 | n++; |
---|
206 | } |
---|
207 | } |
---|
208 | } |
---|
209 | return result; |
---|
210 | } |
---|