1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * Rappture::MeshPrism3D |
---|
4 | * This is a non-uniform 3D mesh, made of triangles in (x,y) and |
---|
5 | * line segments in z. Their product forms triangular prisms. |
---|
6 | * |
---|
7 | * ====================================================================== |
---|
8 | * AUTHOR: Michael McLennan, Purdue University |
---|
9 | * Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
10 | * |
---|
11 | * See the file "license.terms" for information on usage and |
---|
12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | * ====================================================================== |
---|
14 | */ |
---|
15 | #include <assert.h> |
---|
16 | #include "RpMeshPrism3D.h" |
---|
17 | |
---|
18 | using namespace Rappture; |
---|
19 | |
---|
20 | CellPrism3D::CellPrism3D() |
---|
21 | { |
---|
22 | for (int i=0; i < 6; i++) { |
---|
23 | _nodeIds[i] = -1; |
---|
24 | _x[i] = 0.0; |
---|
25 | _y[i] = 0.0; |
---|
26 | _z[i] = 0.0; |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | CellPrism3D::CellPrism3D(const CellPrism3D& cell) |
---|
31 | { |
---|
32 | for (int i=0; i < 6; 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 | CellPrism3D& |
---|
41 | CellPrism3D::operator=(const CellPrism3D& cell) |
---|
42 | { |
---|
43 | for (int i=0; i < 6; 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 | CellPrism3D::nodeId(int n) |
---|
54 | { |
---|
55 | assert(n >= 0 && n < 6); |
---|
56 | return _nodeIds[n]; |
---|
57 | } |
---|
58 | |
---|
59 | double& |
---|
60 | CellPrism3D::x(int n) |
---|
61 | { |
---|
62 | assert(n >= 0 && n < 6); |
---|
63 | return _x[n]; |
---|
64 | } |
---|
65 | |
---|
66 | double& |
---|
67 | CellPrism3D::y(int n) |
---|
68 | { |
---|
69 | assert(n >= 0 && n < 6); |
---|
70 | return _y[n]; |
---|
71 | } |
---|
72 | |
---|
73 | double& |
---|
74 | CellPrism3D::z(int n) |
---|
75 | { |
---|
76 | assert(n >= 0 && n < 6); |
---|
77 | return _z[n]; |
---|
78 | } |
---|
79 | |
---|
80 | int |
---|
81 | CellPrism3D::isOutside() const |
---|
82 | { |
---|
83 | for (int i=0; i < 6; i++) { |
---|
84 | if (_nodeIds[i] < 0) { |
---|
85 | return 1; |
---|
86 | } |
---|
87 | } |
---|
88 | return 0; |
---|
89 | } |
---|
90 | |
---|
91 | MeshPrism3D::MeshPrism3D() |
---|
92 | { |
---|
93 | } |
---|
94 | |
---|
95 | MeshPrism3D::MeshPrism3D(const MeshTri2D& xym, const Mesh1D& zm) |
---|
96 | { |
---|
97 | _xymesh = xym; |
---|
98 | _zmesh = zm; |
---|
99 | } |
---|
100 | |
---|
101 | MeshPrism3D::MeshPrism3D(const MeshPrism3D& mesh) |
---|
102 | : _xymesh(mesh._xymesh), |
---|
103 | _zmesh(mesh._zmesh) |
---|
104 | { |
---|
105 | } |
---|
106 | |
---|
107 | MeshPrism3D& |
---|
108 | MeshPrism3D::operator=(const MeshPrism3D& mesh) |
---|
109 | { |
---|
110 | _xymesh = mesh._xymesh; |
---|
111 | _zmesh = mesh._zmesh; |
---|
112 | return *this; |
---|
113 | } |
---|
114 | |
---|
115 | MeshPrism3D::~MeshPrism3D() |
---|
116 | { |
---|
117 | } |
---|
118 | |
---|
119 | double |
---|
120 | MeshPrism3D::rangeMin(Axis which) const |
---|
121 | { |
---|
122 | if (which == zaxis) { |
---|
123 | return _zmesh.rangeMin(); |
---|
124 | } |
---|
125 | return _xymesh.rangeMin(which); |
---|
126 | } |
---|
127 | |
---|
128 | double |
---|
129 | MeshPrism3D::rangeMax(Axis which) const |
---|
130 | { |
---|
131 | if (which == zaxis) { |
---|
132 | return _zmesh.rangeMax(); |
---|
133 | } |
---|
134 | return _xymesh.rangeMax(which); |
---|
135 | } |
---|
136 | |
---|
137 | CellPrism3D |
---|
138 | MeshPrism3D::locate(const Node3D& node) const |
---|
139 | { |
---|
140 | CellPrism3D result; |
---|
141 | |
---|
142 | Node2D xycoord(node.x(), node.y()); |
---|
143 | CellTri2D xycell = _xymesh.locate(xycoord); |
---|
144 | |
---|
145 | Node1D zcoord(node.z()); |
---|
146 | Cell1D zcell = _zmesh.locate(zcoord); |
---|
147 | |
---|
148 | if (!xycell.isOutside() && !zcell.isOutside()) { |
---|
149 | int n = 0; |
---|
150 | for (int iz=0; iz < 2; iz++) { |
---|
151 | for (int ixy=0; ixy < 3; ixy++) { |
---|
152 | int nxy = xycell.nodeId(ixy); |
---|
153 | int nz = zcell.nodeId(iz); |
---|
154 | if (nxy >= 0 && nz >= 0) { |
---|
155 | result.nodeId(n) = nz*_xymesh.sizeNodes() + nxy; |
---|
156 | result.x(n) = xycell.x(ixy); |
---|
157 | result.y(n) = xycell.y(ixy); |
---|
158 | result.z(n) = zcell.x(iz); |
---|
159 | } |
---|
160 | n++; |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | return result; |
---|
165 | } |
---|