1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * ---------------------------------------------------------------------- |
---|
4 | * NvFlowVisRenderer.cpp: particle system class |
---|
5 | * |
---|
6 | * ====================================================================== |
---|
7 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
8 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
9 | * |
---|
10 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
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 | |
---|
17 | #include <vrmath/Vector3f.h> |
---|
18 | |
---|
19 | #include "NvFlowVisRenderer.h" |
---|
20 | |
---|
21 | using namespace vrmath; |
---|
22 | |
---|
23 | #define NV_32 |
---|
24 | |
---|
25 | NvFlowVisRenderer::NvFlowVisRenderer(int w, int h) : |
---|
26 | _activated(true) |
---|
27 | { |
---|
28 | _psys_width = w; |
---|
29 | _psys_height = h; |
---|
30 | } |
---|
31 | |
---|
32 | NvFlowVisRenderer::~NvFlowVisRenderer() |
---|
33 | { |
---|
34 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
35 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
36 | delete (*iter).second; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | void |
---|
41 | NvFlowVisRenderer::initialize() |
---|
42 | { |
---|
43 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
44 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
45 | (*iter).second->initialize(); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | void |
---|
50 | NvFlowVisRenderer::reset() |
---|
51 | { |
---|
52 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
53 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
54 | (*iter).second->reset(); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | void |
---|
59 | NvFlowVisRenderer::initialize(const std::string& vfName) |
---|
60 | { |
---|
61 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
62 | if (iter != _vectorFieldMap.end()) { |
---|
63 | if ((*iter).second) { |
---|
64 | (*iter).second->initialize(); |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | void |
---|
70 | NvFlowVisRenderer::advect() |
---|
71 | { |
---|
72 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
73 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
74 | if ((*iter).second && (*iter).second->active()) |
---|
75 | (*iter).second->advect(); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | void |
---|
80 | NvFlowVisRenderer::render() |
---|
81 | { |
---|
82 | std::map<std::string, NvVectorField *>::iterator iter; |
---|
83 | for (iter = _vectorFieldMap.begin(); iter != _vectorFieldMap.end(); ++iter) { |
---|
84 | if ((*iter).second && (*iter).second->active()) |
---|
85 | (*iter).second->render(); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | void |
---|
90 | NvFlowVisRenderer::addVectorField(const std::string& vfName, Volume* volPtr, |
---|
91 | const Vector3f& ori, |
---|
92 | float scaleX, float scaleY, float scaleZ, float max) |
---|
93 | { |
---|
94 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
95 | if (iter != _vectorFieldMap.end()) { |
---|
96 | if ((*iter).second) { |
---|
97 | ((*iter).second)->setVectorField(volPtr, ori, scaleX, scaleY, scaleZ, max); |
---|
98 | } else { |
---|
99 | NvVectorField *vf = new NvVectorField(); |
---|
100 | _vectorFieldMap[vfName] = vf; |
---|
101 | vf->setVectorField(volPtr, ori, scaleX, scaleY, scaleZ, max); |
---|
102 | } |
---|
103 | } else { |
---|
104 | NvVectorField *vf = new NvVectorField(); |
---|
105 | _vectorFieldMap[vfName] = vf; |
---|
106 | vf->setVectorField(volPtr, ori, scaleX, scaleY, scaleZ, max); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | void |
---|
111 | NvFlowVisRenderer::activateVectorField(const std::string& vfName) |
---|
112 | { |
---|
113 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
114 | if (iter != _vectorFieldMap.end()) { |
---|
115 | if ((*iter).second) |
---|
116 | (*iter).second->active(true); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | void |
---|
121 | NvFlowVisRenderer::deactivateVectorField(const std::string& vfName) |
---|
122 | { |
---|
123 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
124 | if (iter != _vectorFieldMap.end()) { |
---|
125 | if ((*iter).second) |
---|
126 | (*iter).second->active(false); |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | void |
---|
131 | NvFlowVisRenderer::activatePlane(const std::string& vfName, const std::string& name) |
---|
132 | { |
---|
133 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
134 | if (iter != _vectorFieldMap.end()) { |
---|
135 | if ((*iter).second) |
---|
136 | (*iter).second->activatePlane(name); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | void |
---|
141 | NvFlowVisRenderer::deactivatePlane(const std::string& vfName, const std::string& name) |
---|
142 | { |
---|
143 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
144 | if (iter != _vectorFieldMap.end()) { |
---|
145 | if ((*iter).second) |
---|
146 | (*iter).second->deactivatePlane(name); |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | void |
---|
151 | NvFlowVisRenderer::setPlaneAxis(const std::string& vfName, const std::string& planeName, int axis) |
---|
152 | { |
---|
153 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
154 | if (iter != _vectorFieldMap.end()) { |
---|
155 | if ((*iter).second) |
---|
156 | (*iter).second->setPlaneAxis(planeName, axis); |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | void |
---|
161 | NvFlowVisRenderer::setPlanePos(const std::string& vfName, const std::string& name, float pos) |
---|
162 | { |
---|
163 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
164 | if (iter != _vectorFieldMap.end()) { |
---|
165 | if ((*iter).second) |
---|
166 | (*iter).second->setPlanePos(name, pos); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | void |
---|
171 | NvFlowVisRenderer::setParticleColor(const std::string& vfName, const std::string& name, const Vector4& color) |
---|
172 | { |
---|
173 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
174 | if (iter != _vectorFieldMap.end()) { |
---|
175 | if ((*iter).second) |
---|
176 | (*iter).second->setParticleColor(name, color); |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | void |
---|
181 | NvFlowVisRenderer::removeVectorField(const std::string& vfName) |
---|
182 | { |
---|
183 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
184 | if (iter != _vectorFieldMap.end()) { |
---|
185 | delete (*iter).second; |
---|
186 | _vectorFieldMap.erase(iter); |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | void |
---|
191 | NvFlowVisRenderer::addPlane(const std::string& vfName, const std::string& name) |
---|
192 | { |
---|
193 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
194 | if (iter != _vectorFieldMap.end()) { |
---|
195 | if ((*iter).second) |
---|
196 | (*iter).second->addPlane(name); |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | void |
---|
201 | NvFlowVisRenderer::removePlane(const std::string& vfName, const std::string& name) |
---|
202 | { |
---|
203 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
204 | if (iter != _vectorFieldMap.end()) { |
---|
205 | if ((*iter).second) |
---|
206 | (*iter).second->removePlane(name); |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | void |
---|
211 | NvFlowVisRenderer::activateDeviceShape(const std::string& vfName, const std::string& name) |
---|
212 | { |
---|
213 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
214 | if (iter != _vectorFieldMap.end()) { |
---|
215 | if ((*iter).second) |
---|
216 | (*iter).second->activateDeviceShape(name); |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | void |
---|
221 | NvFlowVisRenderer::deactivateDeviceShape(const std::string& vfName, const std::string& name) |
---|
222 | { |
---|
223 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
224 | if (iter != _vectorFieldMap.end()) { |
---|
225 | if ((*iter).second) |
---|
226 | (*iter).second->deactivateDeviceShape(name); |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | void |
---|
231 | NvFlowVisRenderer::activateDeviceShape(const std::string& vfName) |
---|
232 | { |
---|
233 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
234 | if (iter != _vectorFieldMap.end()) { |
---|
235 | if ((*iter).second) |
---|
236 | (*iter).second->activateDeviceShape(); |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | void |
---|
241 | NvFlowVisRenderer::deactivateDeviceShape(const std::string& vfName) |
---|
242 | { |
---|
243 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
244 | if (iter != _vectorFieldMap.end()) { |
---|
245 | if ((*iter).second) |
---|
246 | (*iter).second->deactivateDeviceShape(); |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | void |
---|
251 | NvFlowVisRenderer::addDeviceShape(const std::string& vfName, const std::string& name, const NvDeviceShape& shape) |
---|
252 | { |
---|
253 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
254 | if (iter != _vectorFieldMap.end()) { |
---|
255 | if ((*iter).second) |
---|
256 | (*iter).second->addDeviceShape(name, shape); |
---|
257 | } |
---|
258 | } |
---|
259 | |
---|
260 | void |
---|
261 | NvFlowVisRenderer::removeDeviceShape(const std::string& vfName, const std::string& name) |
---|
262 | { |
---|
263 | std::map<std::string, NvVectorField *>::iterator iter = _vectorFieldMap.find(vfName); |
---|
264 | if (iter != _vectorFieldMap.end()) { |
---|
265 | if ((*iter).second) |
---|
266 | (*iter).second->removeDeviceShape(name); |
---|
267 | } |
---|
268 | } |
---|